From 3753cf5d5ac8aa206ab42bf71c47ea431f1f7933 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Thu, 24 Oct 2024 22:08:23 +0200 Subject: [PATCH] fix: crash when using do loop with bad type --- src/api/check.py | 3 ++- tests/functional/arch/zx48k/do_crash.bas | 2 ++ tests/functional/cmdline/test_errmsg.txt | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/functional/arch/zx48k/do_crash.bas diff --git a/src/api/check.py b/src/api/check.py index 5b5e0d16e..7c817a6f4 100644 --- a/src/api/check.py +++ b/src/api/check.py @@ -12,6 +12,7 @@ from src.api import config, errmsg, global_ from src.api.constants import CLASS, SCOPE from src.symbols import sym as symbols +from src.symbols.symbol_ import Symbol from src.symbols.type_ import Type __all__ = [ @@ -318,7 +319,7 @@ def is_number(*p): """Returns True if ALL the arguments are AST nodes containing NUMBER or numeric CONSTANTS """ - return all(i.token in ("NUMBER", "CONST") and Type.is_numeric(i.type_) for i in p) + return all(isinstance(i, Symbol) and i.token in ("NUMBER", "CONST") and Type.is_numeric(i.type_) for i in p) def is_static_str(*p): diff --git a/tests/functional/arch/zx48k/do_crash.bas b/tests/functional/arch/zx48k/do_crash.bas new file mode 100644 index 000000000..aeae63fec --- /dev/null +++ b/tests/functional/arch/zx48k/do_crash.bas @@ -0,0 +1,2 @@ +DIM A AS UBYTE +DO LOOP WHILE A = "" diff --git a/tests/functional/cmdline/test_errmsg.txt b/tests/functional/cmdline/test_errmsg.txt index f45bd55ec..49a228bac 100644 --- a/tests/functional/cmdline/test_errmsg.txt +++ b/tests/functional/cmdline/test_errmsg.txt @@ -159,3 +159,8 @@ ND.Controls.bas:4: error: Invalid argument 'dirData' ND.Controls.bas:2: warning: [W150] Variable 'dirData' is never used >>> process_file('arch/zx48k/bad_fname_err4.bas', ['-S', '-q']) ND.Controls.bas:2: error: sub 'Controls_LABEL' declared but not implemented + +# DO LOOP type errors +>>> process_file('arch/zx48k/do_crash.bas', ['-S', '-q']) +do_crash.bas:2: error: Cannot convert string to a value. Use VAL() function +do_crash.bas:2: warning: [W130] Empty loop