- has_tagof on tagged lambdas returns false #2432

This commit is contained in:
Christoffer Lerno
2025-08-23 23:41:32 +02:00
parent a69ee59b82
commit 9bf933ae31
4 changed files with 23 additions and 2 deletions

View File

@@ -63,6 +63,7 @@
- Taking the address of a label would cause a crash. #2430 - Taking the address of a label would cause a crash. #2430
- `@tag` was not allowed to repeat. - `@tag` was not allowed to repeat.
- Lambdas on the top level were not exported by default. #2428 - Lambdas on the top level were not exported by default. #2428
- `has_tagof` on tagged lambdas returns false #2432
### Stdlib changes ### Stdlib changes
- Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`.

View File

@@ -4341,6 +4341,12 @@ INLINE bool expr_is_const_fault(Expr *expr)
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_FAULT; return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_FAULT;
} }
INLINE bool expr_is_const_ref(Expr *expr)
{
ASSERT(expr->resolve_status == RESOLVE_DONE);
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_REF;
}
INLINE bool expr_is_const_pointer(Expr *expr) INLINE bool expr_is_const_pointer(Expr *expr)
{ {
ASSERT(expr->resolve_status == RESOLVE_DONE); ASSERT(expr->resolve_status == RESOLVE_DONE);

View File

@@ -5972,9 +5972,9 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo
{ {
return sema_expr_analyse_type_access(context, expr, parent->type_expr->type, identifier, missing_ref); return sema_expr_analyse_type_access(context, expr, parent->type_expr->type, identifier, missing_ref);
} }
if (parent->expr_kind == EXPR_IDENTIFIER) if (parent->expr_kind == EXPR_IDENTIFIER || expr_is_const_ref(parent))
{ {
Decl *decl = parent->ident_expr; Decl *decl = parent->expr_kind == EXPR_IDENTIFIER ? parent->ident_expr : parent->const_expr.global_ref;
switch (decl->decl_kind) switch (decl->decl_kind)
{ {
case DECL_FUNC: case DECL_FUNC:

View File

@@ -0,0 +1,14 @@
module function_tag;
macro bool @has_tagof_1(#function)
{
return #function.has_tagof("some-tag");
}
fn void tagged_function() @tag("some-tag", true) {}
fn void function_tag() @test
{
assert(@has_tagof_1(tagged_function));
assert(@has_tagof_1(fn void() @tag("some-tag", true) {} ));
}