Manjaro/Arch x86_64, dmd v2.094.1.
dmd complains about a variable declared in a switch case to have skipped its declaration and compilation fails.
Original reduction: https://run.dlang.io/is/ah4XWa
void main()
{
switch (string.init)
{
case "LS":
switch (string.init)
{
case "sasl":
immutable acceptsExternal = true;
goto case;
version (all)
{
case "twitch.tv/membership":
goto case;
}
case "znc.in/self-message":
break;
default:
break;
}
break;
default:
break;
}
}
> feep[work] | zorael: even shorter https://run.dlang.io/is/nrjBkS
void main()
{
final switch ("1")
{
case "1":
immutable acceptsExternal = true;
break;
{
case "2":
break;
}
}
}
> feep[work] | zorael: this is the actual problem https://run.dlang.io/is/IOW91m
void main()
{
final switch ("1")
{
case "1":
immutable acceptsExternal = true;
break;
{
case "2":
return acceptsExternal;
break;
}
}
}
> feep[work] | zorael: workaround https://run.dlang.io/is/as7yjf
void main()
{
switch (string.init)
{
case "LS":
switch (string.init)
{
case "sasl":
immutable acceptsExternal = true;
goto case;
case "THISNEVERHAPPENS": // workaround for weird D switch scoping issue
version (all)
{
case "twitch.tv/membership":
goto case;
}
case "znc.in/self-message":
break;
default:
break;
}
break;
default:
break;
}
}
> feep[work] | zorael: alternately, explicitly wrap the acceptsExternal block in a {}
[...]
> feep[work] | for one, version shouldn't create a scope
> feep[work] | zorael: the actual problem is it thinks that the versioned case is in a subscope and so the variable "should remain in scope"
> feep[work] | which doesn't work cause you can case jump into the versioned case and skip the immutable variable
> feep[work] | so the real issue is that switch thinks version opens a scope (it doesn't even)
Comment #1 by robert.schadek — 2024-12-13T19:13:01Z