[Issue 23744] New: Static If Compilation Differences / Attribute inference bug
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 26 16:47:23 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23744
Issue ID: 23744
Summary: Static If Compilation Differences / Attribute
inference bug
Product: D
Version: D2
Hardware: Other
OS: Mac OS X
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: bradley at chatha.dev
I'm uncertain whether this issue is mainly the "Attribute inference on
recursion" bug or instead another bug that is only manifesting itself alongside
the other bug; but essentially:
```
module test;
bool nextVaryingLengthToken() @safe
{
bool tryLexLongerOperators(alias TokenType)()
{
switch(' ')
{
/*
Comment out the first two blocks and you
will see that the error dissapears.
The only difference between the two
sets of blocks is that one has braces and
the other doesn't.
Additionally, commenting out the line `int i`
will cause the error to not appear.
It appears having _any_ sort of statement there
causes the error to show up.
*/
static if(false)
case "=":
int i;
if(tryLexLongerOperators!"=")
return true;
return true;
static if(false)
case "*":
int i3;
if(tryLexLongerOperators!"*")
return true;
return true;
static if(false)
{
case "=":
int i2;
if(tryLexLongerOperators!"=")
return true;
return true;
case "*":
int i4;
if(tryLexLongerOperators!"*")
return true;
return true;
}
default: return false;
}
}
return tryLexLongerOperators!noreturn;
}
```
It seems that `static if(false) <body>` will still cause the compiler to try
and evaluate the <body>, however `static if(false) { <body> }` causes it to not
bother.
And then since it evaluates the body it triggers the inferrence bug, which is
what makes me think this is a separate bug on its own.
However that's more just an observation rather than a truthful assertion; I'm
struggling to reproduce this outside of this particular setup.
--
More information about the Digitalmars-d-bugs
mailing list