Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `$$atomic_store` and `$$atomic_load` takes an alignment parameter.
- `$vaarg[^1]` is supported. #3276
- Improve error message when a keyword is used a block parameter. #3275
- Correct tag method error messages from `tagof`/`has_tagof` to `get_tag` and `has_tag`

### Stdlib changes
- Add math::TAU / math::TWO_PI
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/sema_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3721,7 +3721,7 @@ static inline bool sema_expr_analyse_typecall(SemaContext *context, Expr *expr)
Expr **args = expr->call_expr.arguments;
unsigned arg_count = vec_size(args);
bool is_has = tag->type_call_expr.property == TYPE_PROPERTY_HAS_TAG;
const char *name = is_has ? "has_tagof" : "tagof";
const char *name = is_has ? "has_tag" : "get_tag";
if (arg_count != 1) RETURN_SEMA_ERROR(expr, "Expected a single string argument to '%s'.", name);
Expr *key = args[0];
if (!sema_analyse_expr_rvalue(context, key)) return false;
Expand Down Expand Up @@ -6494,7 +6494,7 @@ static bool sema_expr_rewrite_to_type_property(SemaContext *context, Expr *expr,
case TYPE_PROPERTY_GET_TAG:
if (!type_is_user_defined(type))
{
RETURN_SEMA_ERROR(expr, "'tagof' is not defined for builtin types like %s.", type_quoted_error_string(type));
RETURN_SEMA_ERROR(expr, "'get_tag' is not defined for builtin types like %s.", type_quoted_error_string(type));
}
FALLTHROUGH;
case TYPE_PROPERTY_HAS_TAG:
Expand Down
10 changes: 10 additions & 0 deletions test/test_suite/compile_time_introspection/tag_methods.c3t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct MyStruct { int a @tag("a", 0); }
fn void main(String[] args) {
$foreach $member : MyStruct::members:
$member.has_tag("a", "a"); // #error: Expected a single string argument to 'has_tag'.
$member.get_tag("a", "a"); // #error: Expected a single string argument to 'get_tag'.
$endforeach
}
fn void test_builtin() {
int::get_tag("key"); // #error: 'get_tag' is not defined for builtin types like 'int'.
}
Loading