www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22284] New: [DIP1000] function templates cannot infer scope

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

          Issue ID: 22284
           Summary: [DIP1000] function templates cannot infer scope in
                    instances with indirections when accessing the address
                    of fields
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jlourenco5691 gmail.com

```
 safe:

struct Foo
{
    void canInfer()() { cast(void) &i; }
    int i;
}

struct Bar
{
    void canInfer1()() { cast(void) arr.ptr; }
    void canInfer2()() { cast(void) &arr[0]; }

    void cannotInfer()()  {            cast(void) &i;      } 
    void cannotInfer1()() { () scope { cast(void) &i; }(); }

    void cannotInfer2(this This)() {            cast(void) &i;      }
    void cannotInfer3(this This)() { () scope { cast(void) &i; }(); }

    void canInfer3(this This)() { (This bar) scope { with(bar) cast(void) &i;
}(this); }
    void canInfer4(this This)() { (This bar)       { with(bar) cast(void) &i;
}(this); }

    int[] arr = [0];
    int i;
}

void main()
{
    scope foo = Foo();
    scope bar = Bar();

    foo.canInfer;
    bar.canInfer1;
    bar.canInfer2;

    bar.cannotInfer;  // fails
    bar.cannotInfer1; // fails
    bar.cannotInfer2; // fails
    bar.cannotInfer3; // fails

    bar.canInfer3; // great...
    bar.canInfer4; // wait what?
}
```

--
Sep 07