@tag was not allowed to repeat.

This commit is contained in:
Christoffer Lerno
2025-08-23 18:42:57 +02:00
parent e4e499edd2
commit 768ce6092d
3 changed files with 15 additions and 0 deletions

View File

@@ -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`.

View File

@@ -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;
}

View File

@@ -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"));
}