www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18282] New: Assignment of local variable to `scope` variable

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

          Issue ID: 18282
           Summary: Assignment of local variable to `scope` variable not
                    recognized by compiler
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: slavo5150 yahoo.com

void main()  safe
{
    string foo = "foo";
    scope string*[] ls;
    ls ~= &foo;
}

Compile with `-dip1000`

onlineapp.d(5): Error: reference to local variable foo assigned to non-scope ls

https://run.dlang.io/is/ecYAKZ

The compiler doesn't seem to recognize that ls is attributed with `scope`. 
However due to the way D's attributes are parsed, I'm not sure if it should
actually be `scope string*[]`, `scope(string*)[]`, or `scope(string*[])`. 
Anyway, if you use `scope()` (i.e. with parens) the compiler confuses it with
`scope(exit)` and friends.


void main()  safe
{
    string foo = "foo";
    scope(string*[]) ls;
    ls ~= &foo;
}

Compile with `-dip1000`

onlineapp.d(4): Error: valid scope identifiers are exit, failure, or success,
not string

https://run.dlang.io/is/ecYAKZ

--
Jan 22