You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since commit edadb20 ("parser: validate attribute declarations", 2026-09-19), the new compiler rejects valid code whenever a struct-level attribute has the same name as a field-level attribute of that struct.
The duplicate check added to parse_field_attrs_with_kinds_mode() also compares the current attribute against p.pending_decl_attrs. While a struct body is parsed, p.pending_decl_attrs still holds the attributes of the enclosing struct declaration, so a field attribute such as @[comment: ...] is falsely reported as a duplicate of the struct-level @[comment: ...].
This pattern is used in V's own tests (vlib/db/pg/pg_orm_test.v, vlib/db/mysql/mysql_orm_test.v), and v -check on them now fails.
The same happens with @[json: 'x'] on the struct and on a field, and with the default compiler (v run main.v). One error is emitted per matching field attribute.
Existing in-tree reproduction:
$ v -check vlib/db/pg/pg_orm_test.v
vlib/db/pg/pg_orm_test.v:47:22: error: duplicate attribute `comment`
TestCommentAttribute has @[comment: 'This is a table comment'] on the struct and @[comment: 'real user name'] on the name field. vlib/db/mysql/mysql_orm_test.v:43 fails the same way.
Expected Behavior
The code compiles. Attributes on a declaration and attributes on its fields are independent scopes; a struct-level @[comment: ...] must not conflict with a field-level @[comment: ...].
Current Behavior
False duplicate attribute errors stop compilation. In a real project this reaches the diagnostic limit:
model/schema_iam/iam_api_key.v:9:19: error: duplicate attribute `comment`
model/schema_iam/iam_api_key.v:10:19: error: duplicate attribute `comment`
...
error: too many errors; stopping after 100 diagnostics
v -old-compiler main.v (V1 fallback) compiles the repro fine; v and v -new-compiler fail, so this is a new-compiler regression.
Possible Solution
The p.pending_decl_attrs comparison is needed for duplicates across separate declaration-level @[...] groups (see vlib/v/parser/tests/fn_attributes_duplicate_multiple.vv), but it must not run while parsing a declaration's fields. Please make that cross-group check apply to declaration attributes only (e.g. pass an explicit flag from parse_pending_decl_attrs()), and add a regression test for a struct with same-named struct-level and field-level attributes.
The offending code, added by edadb20, is in vlib/v/parser/parser.v:3859 at bc640f2:
Describe the bug
Since commit edadb20 ("parser: validate attribute declarations", 2026-09-19), the new compiler rejects valid code whenever a struct-level attribute has the same name as a field-level attribute of that struct.
The duplicate check added to
parse_field_attrs_with_kinds_mode()also compares the current attribute againstp.pending_decl_attrs. While a struct body is parsed,p.pending_decl_attrsstill holds the attributes of the enclosing struct declaration, so a field attribute such as@[comment: ...]is falsely reported as a duplicate of the struct-level@[comment: ...].This pattern is used in V's own tests (
vlib/db/pg/pg_orm_test.v,vlib/db/mysql/mysql_orm_test.v), andv -checkon them now fails.Reproduction Steps
main.v:
The same happens with
@[json: 'x']on the struct and on a field, and with the default compiler (v run main.v). One error is emitted per matching field attribute.Existing in-tree reproduction:
TestCommentAttributehas@[comment: 'This is a table comment']on the struct and@[comment: 'real user name']on thenamefield.vlib/db/mysql/mysql_orm_test.v:43fails the same way.Expected Behavior
The code compiles. Attributes on a declaration and attributes on its fields are independent scopes; a struct-level
@[comment: ...]must not conflict with a field-level@[comment: ...].Current Behavior
False
duplicate attributeerrors stop compilation. In a real project this reaches the diagnostic limit:v -old-compiler main.v(V1 fallback) compiles the repro fine;vandv -new-compilerfail, so this is a new-compiler regression.Possible Solution
The
p.pending_decl_attrscomparison is needed for duplicates across separate declaration-level@[...]groups (seevlib/v/parser/tests/fn_attributes_duplicate_multiple.vv), but it must not run while parsing a declaration's fields. Please make that cross-group check apply to declaration attributes only (e.g. pass an explicit flag fromparse_pending_decl_attrs()), and add a regression test for a struct with same-named struct-level and field-level attributes.The offending code, added by edadb20, is in
vlib/v/parser/parser.v:3859at bc640f2:V version
V 0.5.2 bc640f2 (master, 2026-09-20)
Environment details (OS name and version, etc.)
Linux x86_64, Deepin 25, kernel 6.18.48-amd64-desktop-rolling, gcc 12.3.0.
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.