mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix issue where rethrow in a macro not allowing optional caused an assert to trigger. #849
This commit is contained in:
@@ -152,6 +152,7 @@
|
||||
- Updates to how variadics are implemented.
|
||||
- Fixes to shift checks.
|
||||
- Fixes to string parsing.
|
||||
- Bug when rethrowing an optional from a macro which didn't return an optional.
|
||||
- Fixed issues with ranged cases.
|
||||
- Disallow trailing ',' in function parameter list.
|
||||
- Fixed errors on flexible array slices.
|
||||
|
||||
@@ -6207,6 +6207,12 @@ static inline bool sema_expr_analyse_rethrow(SemaContext *context, Expr *expr)
|
||||
|
||||
if (context->active_scope.flags & (SCOPE_EXPR_BLOCK | SCOPE_MACRO))
|
||||
{
|
||||
TypeInfoId rtype = context->active_scope.flags & SCOPE_MACRO ? context->current_macro->func_decl.signature.rtype : 0;
|
||||
if (rtype && !type_is_optional(typeinfotype(rtype)))
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "Rethrow is only allowed in macros with an optional or inferred return type. "
|
||||
"Did you mean to use '!!' instead?");
|
||||
}
|
||||
vec_add(context->returns, NULL);
|
||||
expr->rethrow_expr.in_block = context->block_exit_ref;
|
||||
expr->rethrow_expr.cleanup = context_get_defers(context, context->active_scope.defer_last, context->block_return_defer, false);
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.4.562"
|
||||
#define COMPILER_VERSION "0.4.563"
|
||||
14
test/test_suite/errors/rethrow_macro.c3
Normal file
14
test/test_suite/errors/rethrow_macro.c3
Normal file
@@ -0,0 +1,14 @@
|
||||
module testing;
|
||||
import std::io;
|
||||
|
||||
macro char[] read(src, allocator, n)
|
||||
{
|
||||
char* data = allocator.alloc(n)!; // #error: Rethrow is only allowed in macros
|
||||
src.read_all(data[:n])!;
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
ByteReader br;
|
||||
read(br.as_stream(), mem::temp(), 10);
|
||||
}
|
||||
Reference in New Issue
Block a user