Incorrect error message when $eval is provided an invalid string. #1570

This commit is contained in:
Christoffer Lerno
2024-10-25 10:31:45 +02:00
parent d8f4da4d90
commit c0c571ffe0
4 changed files with 14 additions and 3 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -0,0 +1,10 @@
import std::io;
fn void main()
{
$eval("foo()"); // #error: with $eval
}
fn void foo()
{
io::printfn("foo");
}