Fix issue where rethrow in a macro not allowing optional caused an assert to trigger. #849

This commit is contained in:
Christoffer Lerno
2023-07-13 12:34:15 +02:00
parent fc316b1031
commit c99f298cad
4 changed files with 22 additions and 1 deletions

View File

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

View File

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

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.562"
#define COMPILER_VERSION "0.4.563"

View 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);
}