Bug 24808 – Semicolon expected after traits

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-10-12T17:25:53Z
Last change time
2024-12-13T19:38:03Z
Assigned to
No Owner
Creator
Tim
Moved to GitHub: dmd#20531 →

Comments

Comment #0 by tim.dlang — 2024-10-12T17:25:53Z
The following code currently results in a syntax error: ``` struct TypeUDA(T) { alias Type = T; } enum E { @TypeUDA!short int16, @TypeUDA!int int32, @TypeUDA!long int64, } alias X = __traits(getAttributes, E.int32)[0].Type; ``` The error message is: ``` test.d(11): Error: semicolon expected to close `alias` declaration, not `.` test.d(11): Error: no identifier for declarator `.Type` ```
Comment #1 by nick — 2024-10-13T09:15:15Z
I think the grammar doesn't support that yet: https://dlang.org/spec/type.html#grammar QualifiedIdentifier: ... Identifier [ AssignExpression ] . QualifiedIdentifier We would need: TraitsExpression [ AssignExpression ] . QualifiedIdentifier
Comment #2 by tim.dlang — 2024-10-13T09:50:04Z
Yes, it looks like this grammar change would be needed. The following also does not compile, so it is consistent: ``` __traits(getAttributes, E.int32)[0].Type x; ``` Alternatively the grammar for BasicType could get: ``` TraitsExpression . QualifiedIdentifier ``` This would be similar to Typeof. The same problem also exists for mixins: ``` alias X1 = mixin("Types")[0].Type; alias X2 = mixin("Types").Type; ``` It is not a high priority. It was just unexpected.
Comment #3 by robert.schadek — 2024-12-13T19:38:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20531 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB