mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Compiler crash when passing an untyped list as an argument to assert #2108.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
- Added missing `@clone_aligned` and add checks to `@tclone`
|
||||
- Comparing a distinct type with an enum with an inline distinct type failed unexpectedly.
|
||||
- The `%s` would not properly print function pointers.
|
||||
- Compiler crash when passing an untyped list as an argument to `assert` #2108.
|
||||
|
||||
### Stdlib changes
|
||||
- Hash functions for integer vectors and arrays.
|
||||
|
||||
@@ -115,7 +115,25 @@ static inline bool sema_analyse_assert_stmt(SemaContext *context, Ast *statement
|
||||
{
|
||||
if (!sema_analyse_expr(context, e)) return false;
|
||||
if (IS_OPTIONAL(e)) RETURN_SEMA_ERROR(e, "Optionals cannot be used as assert arguments, use '?""?', '!' or '!!' to fix this.");
|
||||
if (type_is_void(e->type)) RETURN_SEMA_ERROR(e, "This expression is of type 'void', did you make a mistake?");
|
||||
switch (sema_resolve_storage_type(context, e->type))
|
||||
{
|
||||
case STORAGE_ERROR:
|
||||
return false;
|
||||
case STORAGE_NORMAL:
|
||||
break;
|
||||
case STORAGE_WILDCARD:
|
||||
UNREACHABLE
|
||||
case STORAGE_VOID:
|
||||
RETURN_SEMA_ERROR(e, "This expression is of type 'void', did you make a mistake?");
|
||||
case STORAGE_COMPILE_TIME:
|
||||
if (e->type == type_untypedlist)
|
||||
{
|
||||
RETURN_SEMA_ERROR(e, "The type of an untyped list cannot be inferred, you can try adding an explicit type to solve this.");
|
||||
}
|
||||
RETURN_SEMA_ERROR(e, "You can't use a compile time type as an assert argument.");
|
||||
case STORAGE_UNKNOWN:
|
||||
RETURN_SEMA_ERROR(e, "You can't use an argument of type %s in an assert.", type_quoted_error_string(e->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
test/test_suite/assert/assert_arguments_ct.c3
Normal file
18
test/test_suite/assert/assert_arguments_ct.c3
Normal file
@@ -0,0 +1,18 @@
|
||||
import std;
|
||||
macro @test(#e1, #e2) {
|
||||
assert(
|
||||
#e1 == #e2,
|
||||
"Assertion '" +++ $stringify(#e1) +++ " == " +++ $stringify(#e2)
|
||||
+++ "' failed, got '%s', expected '%s'.", #e1, #e2 // #error: untyped list cannot be inferred
|
||||
);
|
||||
}
|
||||
|
||||
fn usz[<2>] grapheme_length(char*)
|
||||
{
|
||||
return { 1, 1 };
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
@test(grapheme_length("a"), { 1, 1 });
|
||||
}
|
||||
Reference in New Issue
Block a user