Bug 22184 – Template instantiation in static ifs in mutual recursion classes fail
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2021-08-06T12:10:34Z
Last change time
2022-09-23T09:43:43Z
Assigned to
No Owner
Creator
Tomoya Tanjo
Comments
Comment #0 by ttanjo — 2021-08-06T12:10:34Z
The following code works with dmd 2.096.1 (uses sumtype via dub) but does not work since dmd 2.097.0 (uses sumtype or std.sumtype).
I'm not sure it is a regression of std.sumtype or dmd. I tentatively set the `Component` field to `phobos`.
run.dang.io
- (sumtype): https://run.dlang.io/is/IiGESU
- (std.sumtype): https://run.dlang.io/is/j8rqve
```dlang
import std.sumtype;
class A
{
SumType!B type;
}
class B
{
SumType!C fields;
}
class C
{
SumType!(B, int) type;
}
```
Error message:
```console
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/traits.d(191): Error: forward reference of variable `isHashable`
/dlang/dmd/linux/bin64/../../src/phobos/std/meta.d(842): Error: template instance `core.internal.traits.allSat!(isHashable, const(B), const(int))` error instantiating
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(771): instantiated from here: `allSatisfy!(isHashable, const(B), const(int))`
onlineapp.d(15): instantiated from here: `SumType!(B, int)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/traits.d(191): Error: template instance `std.sumtype.pred!(const(C))` error instantiating
/dlang/dmd/linux/bin64/../../src/phobos/std/meta.d(842): instantiated from here: `allSat!(isHashable, const(C))`
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(771): instantiated from here: `allSatisfy!(isHashable, const(C))`
onlineapp.d(10): instantiated from here: `SumType!(C)`
/dlang/dmd/linux/bin64/../../src/druntime/import/core/internal/traits.d(191): Error: template instance `std.sumtype.pred!(const(B))` error instantiating
/dlang/dmd/linux/bin64/../../src/phobos/std/meta.d(842): instantiated from here: `allSat!(isHashable, const(B))`
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(771): instantiated from here: `allSatisfy!(isHashable, const(B))`
onlineapp.d(5): instantiated from here: `SumType!(B)`
```
Notes:
- It works if `A` is not available
- It works if `C` has a field whose type is `SumType!B` rather than `SumType!(B, int)`
I reduced the above code as follows:
run.dlang.io: https://run.dlang.io/is/VZtiPO
```dlang
class A
{
static if (isHashable!B) {}
}
class B
{
static if (isHashable!C) {}
}
class C
{
static if (isHashable!B && isHashable!int) {}
}
enum isHashable(T) = __traits(compiles,
() { T.init; }
);
void main(){}
```
- It compiles successfully if `isHashable` checks `T t;` rather than `T.init;`
Comment #3 by ttanjo — 2021-08-11T14:38:27Z
I fixed the issue title and the `Component` section because it is a issue of dmd rather than std.sumtype.
Comment #4 by ttanjo — 2021-08-13T17:33:06Z
Sorry, I found that I made an inappropriate reproducible code for the issue.
The first example fails both of dmd 2.096.1 and dmd 2.097.0.
Please close this issue as invalid.
Comment #5 by snarwin+bugzilla — 2021-08-13T20:46:13Z
Even if it's not a regression, it's still a valid issue. I'll change the category to "normal" and leave it open for now.
Possibly related to issue 20443.
Comment #6 by ttanjo — 2022-09-23T09:43:43Z
I close this issue because the first example now works with dmd 2.100.2.
However, the reduced example still does not work.
I will make a comment about the reduced case to the issue 20443 instead of keep open this issue.