diff --git a/releasenotes.md b/releasenotes.md index 56b2e75ce..216429288 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -60,6 +60,7 @@ - Failed to find subscript overloading on optional values. - `Socket.get_option` didn't properly call `getsockopt`, and `getsockopt` had an invalid signature. - Taking the address of a label would cause a crash. #2430 +- `@tag` was not allowed to repeat. ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index e419c4ffc..0fe3d8e15 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -1287,12 +1287,14 @@ static inline bool parse_attribute_list(ParseContext *c, Attr ***attributes_ref, *visibility_ref = visibility = parsed_visibility; continue; } + if (attr->attr_kind == ATTRIBUTE_TAG) goto ADD; } const char *name = attr->name; FOREACH(Attr *, other_attr, *attributes_ref) { if (other_attr->name == name) RETURN_PRINT_ERROR_AT(false, attr, "Repeat of attribute '%s' here.", name); } +ADD: vec_add(*attributes_ref, attr); if (use_comma && !try_consume(c, TOKEN_COMMA)) break; } diff --git a/test/test_suite/compile_time_introspection/tag_multiple.c3t b/test/test_suite/compile_time_introspection/tag_multiple.c3t new file mode 100644 index 000000000..43ba5217a --- /dev/null +++ b/test/test_suite/compile_time_introspection/tag_multiple.c3t @@ -0,0 +1,12 @@ +struct Foo @tag("a", true) @tag("b", false) +{ + int a; +} +fn void main() +{ + Foo x; + $assert(Foo.has_tagof("b")); + $assert(Foo.has_tagof("a")); + $assert(Foo.tagof("a")); + $assert(!Foo.tagof("b")); +} \ No newline at end of file