Bug 20831 – __traits(getAttributes) failes to compile when used on a parameter with no name
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-05-14T14:23:28Z
Last change time
2020-06-17T02:16:24Z
Keywords
pull
Assigned to
No Owner
Creator
Atila Neves
Comments
Comment #0 by atila.neves — 2020-05-14T14:23:28Z
With dmd v2.091.1, this code fails to compile (it doesn't even print fail in the pragma, it just doesn't compile):
----------------------------------------
void foo(int f, float, @("test") string s = "test") {}
static if(is(typeof(foo) Params == __parameters))
pragma(msg, __traits(getAttributes, Params[1..2]));
else
pragma(msg, "fail");
----------------------------------------
But moving the code to a function makes it work somehow:
----------------------------------------
void foo(int f, float, @("test") string s = "test") {}
void main() {
static if(is(typeof(foo) Params == __parameters))
pragma(msg, __traits(getAttributes, Params[1..2]));
else
pragma(msg, "fail");
}
----------------------------------------
The 2nd version correctly prints "tuple()". In the 1st non-working version, naming the 2nd parameter also makes the problem go away.
Comment #1 by destructionator — 2020-05-14T14:26:07Z
I simplified the test a little more and see it changes based on order:
```
void main() {
static if(is(typeof(foo) Params == __parameters))
pragma(msg, __traits(getAttributes, Params[0..1]));
}
void foo(float) {}
```
That triggers it. Now move the definition of `foo` up above main:
```
void foo(float) {}
void main() {
static if(is(typeof(foo) Params == __parameters))
pragma(msg, __traits(getAttributes, Params[0..1]));
}
```
that works correctly. Looks like one of those semantic is not called at the right time bugs.
Comment #2 by dlang-bot — 2020-06-16T12:13:11Z
@BorisCarvajal created dlang/dmd pull request #11284 "Fix Issue 20831 - __traits(getAttributes) failes to compile when used…" fixing this issue:
- Fix Issue 20831 - __traits(getAttributes) failes to compile when used on a parameter with no name
https://github.com/dlang/dmd/pull/11284
Comment #3 by dlang-bot — 2020-06-17T02:16:24Z
dlang/dmd pull request #11284 "Fix Issue 20831 - __traits(getAttributes) failes to compile when used…" was merged into master:
- a5d42258a8ac5e331ad3490273ceff956eb00283 by Boris Carvajal:
Fix Issue 20831 - __traits(getAttributes) failes to compile when used on a parameter with no name
https://github.com/dlang/dmd/pull/11284