digitalmars.D - Is this a bug in Nullable or in compiler?
- Andrey Zherikov (27/27) Nov 28 2022 The following code doesn't compile:
- Andrey Zherikov (9/9) Nov 28 2022 If I replace `Nullable` with `SumType!(None,S)` then everything
- Steven Schveighoffer (11/21) Nov 28 2022 It's just a forward reference bug.
The following code doesn't compile: ```d struct S { Nullable!S delegate() f; } ``` Output from DMD: ``` /dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/traits.d(345): Error: unable to determine fields of `S` because of forward references /dlang/dmd/linux/bin64/../../src/phobos/std/traits.d(3327): Error: template instance `core.internal.traits._hasIndirections!(S)` error instantiating /dlang/dmd/linux/bin64/../../src/phobos/std/typecons.d(2768): instantiated from here: `hasIndirections!(S)` onlineapp.d(4): instantiated from here: `Nullable!(S)` /dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/traits.d(16): Error: unable to determine fields of `S` because of forward references /dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/traits.d(269): Error: template instance `core.internal.traits.Fields!(S)` error instantiating /dlang/dmd/linux/bin64/../../src/phobos/std/typecons.d(2790): instantiated from here: `hasElaborateDestructor!(S)` onlineapp.d(4): instantiated from here: `Nullable!(S)` ``` I'm not sure whether it's a big in Nullable or in compiler because `pragma(msg, S.sizeof)` doesn't work either. I tried different variants like `function` instead of `delegate` and putting `Nullable` to parameters like `void function(Nullable!S) f;` - but they don't work either.
Nov 28 2022
If I replace `Nullable` with `SumType!(None,S)` then everything works: ```d struct None {} struct S { SumType!(None,S) delegate() f; } ```
Nov 28 2022
On 11/28/22 6:07 AM, Andrey Zherikov wrote:The following code doesn't compile: ```d struct S { Nullable!S delegate() f; } ```I tried different variants like `function` instead of `delegate` and putting `Nullable` to parameters like `void function(Nullable!S) f;` - but they don't work either.It's just a forward reference bug. This seems to fix it: ```d alias NS = Nullable!S; struct S { Nullable!S delegate() f; } ``` -Steve
Nov 28 2022