www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22117] New: Can't store scope pointer in a SumType


          Issue ID: 22117
           Summary: Can't store scope pointer in a SumType
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

As of DMD 2.097.0, the following program fails to compile with

void main()  safe
    import std.sumtype;
    int n = 123;
    SumType!(int*) s = &n;

The error message is:

Error: reference to local variable `n` assigned to non-scope parameter `value`
calling std.sumtype.SumType!(int*).SumType.this

Since the sumtype instance `s` is a local variable with shorter lifetime than
`n`, it should be able to store a pointer to `n`.

Jul 11 2021