diff --git a/releasenotes.md b/releasenotes.md index 39afb35ca..e971ff0c7 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 6e065c767..4fa1be38c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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; @@ -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: diff --git a/test/test_suite/compile_time_introspection/tag_methods.c3t b/test/test_suite/compile_time_introspection/tag_methods.c3t new file mode 100644 index 000000000..94b5b97ee --- /dev/null +++ b/test/test_suite/compile_time_introspection/tag_methods.c3t @@ -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'. +} \ No newline at end of file