diff --git a/releasenotes.md b/releasenotes.md index 4424ff3df..87a2b8443 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -12,6 +12,7 @@ - Optional does not play well with bit ops #2618. - `Bytebuffer.grow` was broken #2622. - Hex escapes like `"\x80"` would be incorrectly lowered. #2623 +- Ignore const null check on deref in `$defined` and `$sizeof` #2633. ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index fac18bc7c..46358a21e 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -6085,7 +6085,7 @@ TYPE_CALL: bool sema_expr_rewrite_insert_deref(SemaContext *context, Expr *original) { - if (expr_is_const_pointer(original) && !original->const_expr.ptr) + if (expr_is_const_pointer(original) && !original->const_expr.ptr && !context->call_env.in_no_eval) { RETURN_SEMA_ERROR(original, "This value is known to be null so you cannot dereference it."); } diff --git a/test/test_suite/compile_time_introspection/defined_null_deref_check.c3t b/test/test_suite/compile_time_introspection/defined_null_deref_check.c3t new file mode 100644 index 000000000..68417885c --- /dev/null +++ b/test/test_suite/compile_time_introspection/defined_null_deref_check.c3t @@ -0,0 +1,10 @@ +module test; +import std; + +fn int main() +{ + int x @if($defined((char*){}.is_digit())); + isz s = $sizeof((char*){}.is_digit()); + $typeof((char*){}.is_digit()) t; + return 0; +} \ No newline at end of file