www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21209] New: scope attribute inference with does not work well


          Issue ID: 21209
           Summary: scope attribute inference with does not work well with
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: rightfold+bugzilla+dlang gmail.com

The following program does not compile:

$ cat main.d
void foo()(const(char)[] cs)
    foreach (c; cs)

void bar(char c)

void main()
    char[10] cs;
    foo(cs); // line 16
$ dmd -dip1000 main.d
main.d(16): Error: reference to local variable `cs` assigned to non-scope
parameter `cs` calling example.foo!().foo

By manually adding the scope attribute to the cs parameter, the program
compiles. But it is expected that DMD infers this from the body of the foo
function, as it is a template.

Verified with DMD 2.092.0 and LDC 1.23.0.

Aug 29 2020