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.
After some thought and tinkering I don't think this is actually a bug but more an edgecase.
```
static if(false);
```
Comment #3 by bradley — 2023-04-03T07:20:15Z
Apologies, I forget using tab in a browser text editor is generally unwise :D
Anyway:
```
static if(false)
case 0:
yada...
break;
```
The static if (also works for static foreach) only attached itself to the resulting `case 0:` AST Node; leaving the 'body' of the case in some strange limbo state, causing semantic errors.
Which fully explains some of the weirdness displayed, especially why brackets removes the issue.
Comment #4 by bradley — 2023-04-03T07:28:41Z
Minimal reproduction:
```
void main()
{
switch(0)
{
static if (false)
case 0:
int a;
a = 0;
break;
default: break;
}
}
```
I guess case labels also directly attach onto the next statement; which explains some other behaviour I've seen (namely the attached statement being omitted).
Comment #5 by robert.schadek — 2024-12-13T19:27:26Z