Skip to content

Commit

Permalink
🎨 update
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Mar 14, 2024
1 parent a6d050c commit 59e867a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/sema_private.h
Expand Up @@ -10,6 +10,7 @@ typedef struct {
bool scope;
bool handling;
bool in_variadic;
bool in_defer;
} Sema;

#ifdef __SEMA_IMPLEMENTATION__
Expand Down
17 changes: 14 additions & 3 deletions src/sema/sema.c
Expand Up @@ -331,6 +331,11 @@ ANN static bool sema_stmt_return(Sema *a, Stmt_Exp b) {
POISON(a, stmt_self(b));
ok = false;
}
if(a->in_defer) {
gwerr_basic("'return' statement in defered action", NULL, NULL, a->filename, stmt_self(b)->loc, 0);
POISON(a, stmt_self(b));
ok = false;
}
if(b->val && !unique_expression(a, b->val, "in `return` statement"))
ok = false;
return ok;
Expand Down Expand Up @@ -377,7 +382,7 @@ ANN static bool sema_stmt_pp(Sema *a, Stmt_PP b) {

ANN static bool sema_stmt_retry(Sema *a NUSED, Stmt_Exp b NUSED) {
if(a->handling) return true;
gwerr_basic("`retry outside of `handle` block", NULL, NULL, a->filename, stmt_self(b)->loc, 0);
gwerr_basic("`retry` outside of `handle` block", NULL, NULL, a->filename, stmt_self(b)->loc, 0);
return false;
}

Expand Down Expand Up @@ -422,7 +427,10 @@ ANN static bool sema_stmt_try(Sema *a, Stmt_Try b) {
}

ANN static bool sema_stmt_defer(Sema *a, Stmt_Defer b) {
const bool in_defer = a ->in_defer;
a->in_defer = true;
return sema_stmt(a, b->stmt, false);
a ->in_defer = in_defer;
}

ANN2(1, 2) static bool sema_spread(Sema *a, const Spread_Def spread, MP_Vector **acc) {
Expand Down Expand Up @@ -662,20 +670,23 @@ ANN static bool sema_func_def(Sema *a, Func_Def b) {
const Tmpl *tmpl = b->base->tmpl;
const bool is_base = tmpl && tmpl_base(tmpl);
const bool is_spread = tmpl && is_spread_tmpl(tmpl);
const bool in_variadic = a->in_variadic;
const bool is_fill = !is_base && is_spread;
const bool in_variadic = a->in_variadic;
const bool in_defer = a->in_defer;
a->in_variadic = in_variadic || is_spread;
a->in_defer = in_defer;
if(is_fill && !fill(a, tmpl))
return false;
bool ok = sema_func_base(a, b->base, !GET_FLAG(b->base, abstract));
if(b->d.code) {
const bool func = a->func;
a->func = true;
a->func = true; // we can move this out
(void)sema_stmt_list(a, &b->d.code); // ignore code in return value
a->func = func;
}
if(is_fill) unfill(a, tmpl);
a->in_variadic = in_variadic;
a->in_defer = in_defer;
return ok;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/try-handle/duplicate_handler.gw
@@ -0,0 +1,6 @@
#! [contains] duplicate handler tag
try {

} handle Foo {
} handle Foo {}

3 changes: 3 additions & 0 deletions tests/try-handle/retry_outside_handle.gw
@@ -0,0 +1,3 @@

#! [contains] `retry` outside of `handle` block
retry;

0 comments on commit 59e867a

Please sign in to comment.