From c0c571ffe0d1d04997a8b31339a111823d05cfb8 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 25 Oct 2024 10:31:45 +0200 Subject: [PATCH] Incorrect error message when `$eval` is provided an invalid string. #1570 --- releasenotes.md | 1 + src/compiler/sema_expr.c | 4 ++-- src/compiler/sema_types.c | 2 +- test/test_suite/compile_time/ct_eval_wrong.c3 | 10 ++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/test_suite/compile_time/ct_eval_wrong.c3 diff --git a/releasenotes.md b/releasenotes.md index f9ff2a437..d051cb396 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -45,6 +45,7 @@ - `if (try foo)` was handled incorrectly inside a defer. - `&self` argument not implicitly null checked. #1556. - `(uptr)&((Foo*)null).a` incorrectly inserts a null check. #1544 +- Incorrect error message when `$eval` is provided an invalid string. #1570 ### Stdlib changes - Remove unintended print of `char[]` as String diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index ec1899499..901ca2138 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -8077,7 +8077,7 @@ RETRY: case TYPE_INFO_EVALTYPE: { Expr *expr = type_info->unresolved_type_expr; - expr = sema_ct_eval_expr(context, "$evaltype", expr, false); + expr = sema_ct_eval_expr(context, true, expr, false); if (!expr) return NULL; if (expr->expr_kind != EXPR_TYPEINFO) { @@ -8869,7 +8869,7 @@ static inline bool sema_expr_analyse_ct_eval(SemaContext *context, Expr *expr, C { TokenType type; Path *path = NULL; - Expr *result = sema_ct_eval_expr(context, "$eval", expr->inner_expr, true); + Expr *result = sema_ct_eval_expr(context, false, expr->inner_expr, true); if (!result) return false; if (result->expr_kind == EXPR_TYPEINFO) { diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 94dcf31f1..5c21de70a 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -282,7 +282,7 @@ static bool sema_resolve_type_identifier(SemaContext *context, TypeInfo *type_in INLINE bool sema_resolve_evaltype(SemaContext *context, TypeInfo *type_info, ResolveTypeKind resolve_kind) { Expr *expr = type_info->unresolved_type_expr; - Expr *inner = sema_ct_eval_expr(context, "$evaltype", expr, true); + Expr *inner = sema_ct_eval_expr(context, true, expr, true); if (!inner) return type_info_poison(type_info); if (inner->expr_kind != EXPR_TYPEINFO) { diff --git a/test/test_suite/compile_time/ct_eval_wrong.c3 b/test/test_suite/compile_time/ct_eval_wrong.c3 new file mode 100644 index 000000000..e6a11fdb5 --- /dev/null +++ b/test/test_suite/compile_time/ct_eval_wrong.c3 @@ -0,0 +1,10 @@ +import std::io; + +fn void main() +{ + $eval("foo()"); // #error: with $eval +} +fn void foo() +{ + io::printfn("foo"); +} \ No newline at end of file