From 3688f6912317b34032d5c85656aaa26ec58f61d1 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 18 Jun 2025 00:12:24 +0800 Subject: [PATCH] fix `read_literal` --- include/pocketpy/objects/error.h | 2 +- src/compiler/compiler.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/pocketpy/objects/error.h b/include/pocketpy/objects/error.h index d483767c..f80b1ad4 100644 --- a/include/pocketpy/objects/error.h +++ b/include/pocketpy/objects/error.h @@ -6,7 +6,7 @@ typedef struct{ SourceData_ src; int lineno; - char msg[100]; + char msg[512]; } Error; void py_BaseException__stpush(py_Ref, SourceData_ src, int lineno, const char* func_name); diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 4a02bad3..68919618 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -2346,7 +2346,9 @@ static Error* read_literal(Compiler* self, py_Ref out) { } return NULL; } - default: py_newnil(out); return NULL; + default: { + return SyntaxError(self, "expected a literal, got '%s'", TokenSymbols[prev()->type]); + } } } @@ -2385,7 +2387,6 @@ static Error* _compile_f_args(Compiler* self, FuncDecl* decl, bool is_lambda) { consume(TK_ASSIGN); py_TValue value; check(read_literal(self, &value)); - if(py_isnil(&value)) return SyntaxError(self, "default argument must be a literal"); FuncDecl__add_kwarg(decl, name, &value); } break; case 3: