[Issue 21990] New: scope inference fails with foreach on AliasSeq

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 3 08:00:33 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21990

          Issue ID: 21990
           Summary: scope inference fails with foreach on AliasSeq
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

Continuation of issue 21209

Scope inference fails on foreach loops of tuples / alias sequences:

```
@safe:
void foo(A...)(A args) 
{
    static int x; x++; // force impure for issue 20150
    foreach(a; args) 
    {
        // gets lowered to unrolled loop with `string a = _param_0;`
    }
}

void main() 
{
    scope string x = "hey";
    foo(x);
}
```

Error: scope variable `x` assigned to non-scope parameter `_param_0` calling
foo!string.foo

It gets lowered to a special 'unrolled' loop which puts the loop variable in a
temporary (`string a = _param_0;`), which makes _param_0 non-scope.

--


More information about the Digitalmars-d-bugs mailing list