Thread overview
A variation of issue 11977?
Jan 21, 2021
kdevel
Jan 21, 2021
Paul Backus
Jan 21, 2021
kdevel
Jan 21, 2021
z
Jan 21, 2021
kdevel
January 21, 2021
~~~gotoskip.d
int main ()
{
   string[string] aa;
   goto A;               // line 4
   aa["X"] = "Y";        // line 5
A:
   return 0;
}
~~~

$ dmd gotoskip.d
gotoskip.d(4): Error: goto skips declaration of variable gotoskip.main.__aaval2 at gotoskip.d(5)

What's wrong here? Only found Issue 11977 [1] in which a declaration and
initialization is jumped over. However, the statement in line 5 is neither
a declaration nor an initialization.

[1] https://issues.dlang.org/show_bug.cgi?id=11977
January 21, 2021
On Thursday, 21 January 2021 at 13:55:48 UTC, kdevel wrote:
> ~~~gotoskip.d
> int main ()
> {
>    string[string] aa;
>    goto A;               // line 4
>    aa["X"] = "Y";        // line 5
> A:
>    return 0;
> }
> ~~~
>
> $ dmd gotoskip.d
> gotoskip.d(4): Error: goto skips declaration of variable gotoskip.main.__aaval2 at gotoskip.d(5)
>
> What's wrong here? Only found Issue 11977 [1] in which a declaration and
> initialization is jumped over. However, the statement in line 5 is neither
> a declaration nor an initialization.
>
> [1] https://issues.dlang.org/show_bug.cgi?id=11977

__aaval2 is a compiler-generated temporary variable. If you comment out the `goto A;` (so that the code compiles) and use the compiler flag -vcg-ast, you can see its declaration:

int main()
{
	string[string] aa = null;
        // goto A;
	(string __aaval2 = "Y";) , aa["X"] = __aaval2;
	A:
	return 0;
}
January 21, 2021
On Thursday, 21 January 2021 at 13:55:48 UTC, kdevel wrote:
>    goto A;               // line 4
>    aa["X"] = "Y";        // line 5
> A:

Creating a scope

   { aa["X"] = "Y"; }      // line 5

works around the issue.
January 21, 2021
On Thursday, 21 January 2021 at 13:55:48 UTC, kdevel wrote:

[...]

created https://issues.dlang.org/show_bug.cgi?id=21571
January 21, 2021
On Thursday, 21 January 2021 at 14:11:15 UTC, kdevel wrote:
> Creating a scope
> works around the issue.

Another way to work around the issue is to use «asm {jmp label;}» (replace jmp by whatever equivalent is there on the target architecture.)
Yes it's ugly, but it bypasses the arbitrary limitation perfectly.