Issue 22184 - Template instantiation in static ifs in mutual recursion classes fail
Summary: Template instantiation in static ifs in mutual recursion classes fail
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-06 12:10 UTC by Tomoya Tanjo
Modified: 2022-09-23 09:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomoya Tanjo 2021-08-06 12:10:34 UTC
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)`
Comment 1 Tomoya Tanjo 2021-08-06 12:30:20 UTC
It works if we declare the classes in the following order: C, A and B.

run.dlang.io: https://run.dlang.io/is/qRsc7e
Comment 2 Tomoya Tanjo 2021-08-11 14:29:08 UTC
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 Tomoya Tanjo 2021-08-11 14:38:27 UTC
I fixed the issue title and the `Component` section because it is a issue of dmd rather than std.sumtype.
Comment 4 Tomoya Tanjo 2021-08-13 17:33:06 UTC
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 Paul Backus 2021-08-13 20:46:13 UTC
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 Tomoya Tanjo 2022-09-23 09:43:43 UTC
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.