diff --git a/releasenotes.md b/releasenotes.md index 7fb421b2c..95b368ee9 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -13,6 +13,7 @@ - Infer now works across ternary. - Interfaces now support .ptr and .type directly without casting to `any`. - Switch to `<* *>` docs. +- Improve error messages on expressions like `var $type = int;` #1553. ### Fixes - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. @@ -35,6 +36,7 @@ - Standard library is now correctly weakly linked, fixing the use of C3 .so together with executable. #1549, #1107. - Wrong error message for interface methods with body #1536. - Empty expression block would crash compiler with debug on #1554. + ### Stdlib changes - Remove unintended print of `char[]` as String - Add read/write to stream with big endian ints. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 51841ad7c..e40c04ffa 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3746,6 +3746,11 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl) // If we don't have a type, resolve the expression. if ((init = decl->var.init_expr)) { + if (init->expr_kind == EXPR_TYPEINFO) + { + SEMA_ERROR(init, "You can't assign a type to a regular compile time variable like '%s', but it would be allowed if the variable was a compile time type variable. Such a variable needs to have a type-like name, e.g. '$MyType'.", decl->name); + goto FAIL; + } if (!sema_analyse_expr(context, init)) goto FAIL; // Check it is constant. if (!expr_is_runtime_const(init))