www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24430] New: Nested Recursive SumType ICE and destructor issue

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

          Issue ID: 24430
           Summary: Nested Recursive SumType ICE and destructor issue
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kirsybuu gmail.com

If I define this nested sumtype using `This` to be recursive:

```d
import std.sumtype;
struct X {
    SumType!(int, SumType!(int,This)[]) value;
}
```

then the compiler gives this error:

```console
Error: unknown, please file report on issues.dlang.org
onlineapp.d(3): Error: template instance `std.sumtype.SumType!(int, This)`
error instantiating
```

Also, if instead I replace `This` with the wrapping struct:

```d
import std.sumtype;
struct X {
    SumType!(int, SumType!(int,X)[]) value;
}
```

then this static assert fails within the match statement in sumtype's
destructor:

```console
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(2018): Error: static
assert:  "No matching handler for types `(X)`"
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(1649):       
instantiated from here: `matchImpl!(SumType!(int, X))`
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(752):        instantiated
from here: `match!(SumType!(int, X))`
onlineapp.d(3):        instantiated from here: `SumType!(int, X)`
```

Small modifications that also error:
```d
    SumType!(int, SumType!(int,This)*) value; // Error: unknown ...
    SumType!(int, Tuple!(int,X)[]) value; // Error: unknown ...
```

Small modifications that don't error:
```d
    SumType!(int, SumType!(int,X)*) value;
    SumType!(int, SumType!(int,X*)[]) value;
    SumType!(int, SumType!(int,This*)[]) value;
    SumType!(int, Tuple!(int,This)[]) value;
    SumType!(int, Tuple!(int,X)*) value;
    SumType!(int, Tuple!(int,This)*) value;
    SumType!(int,This[]) value;
    SumType!(int,X[]) value;
```

Error output is from run.dlang.io and is similar on all settings of dmd/ldc and
versions since std.sumtype was released.

Possibly similar 2022 issue marked as FIXED:
https://issues.dlang.org/show_bug.cgi?id=22860

--
Mar 05