Reduced:
----
interface Foo
{
Foo troll();
}
abstract class Barbee : Foo {}
class Bar : Barbee
{
Bar troll() { return this; }
}
void main()
{
Foo foo = new Bar;
assert(foo is foo.troll); /* Fails. Should pass. */
}
----
Comment #2 by iamthewilsonator — 2018-09-28T10:54:55Z
This appears to be a missing an offset somewhere.
printf("%p", foo); //0x7fe552a44010
printf("%p", foo.troll); //0x7fe552a44000
It fails also with LDC so the problem is likely a missed cast in the frontend.
Note that:
interface Foo
{
Foo troll();
}
abstract class Barbee : Foo {}
class Bar : Barbee
{
/*Bar*/ Foo troll() { return this; }
}
Works. and
interface Foo
{
Foo troll();
}
abstract class Barbee : Foo {}
//alias Barbee = Foo;
class Bar : Barbee
{
Bar troll() { return this; }
}
void main()
{
Foo foo = new Bar;
auto troll = cast(Barbee)foo.troll; // ICE's
assert(foo is troll);
}
ICE's
Comment #3 by iamthewilsonator — 2018-09-28T11:04:17Z
Sorry that segfaults not ICE's
Comment #4 by dlang-bot — 2021-03-24T08:42:28Z
@puneet created dlang/dmd pull request #12302 "Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <…" fixing this issue:
- Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <- abstract class <- class hierarchies
While analyzing covariant methods, dmd semantic analyzer searched for
immediate interfaces of the class that may have a vtbl entry matching
the method. This failed for possible scenarios where the covariant
method may be declared in an interface inheritance of an abstract base
class.
The fix adds a for loop that iterates over the base classes to find
the relevant interface with matching vtbl entry.
https://github.com/dlang/dmd/pull/12302
Comment #5 by dlang-bot — 2021-03-24T12:39:25Z
dlang/dmd pull request #12302 "Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <…" was merged into stable:
- a7427a67219ed0d8095e0e545b0d73f9e8237906 by Puneet Goel:
Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <- abstract class <- class hierarchies
While analyzing covariant methods, dmd semantic analyzer searched for
immediate interfaces of the class that may have a vtbl entry matching
the method. This failed for possible scenarios where the covariant
method may be declared in an interface inheritance of an abstract base
class.
The fix adds a for loop that iterates over the base classes to find
the relevant interface with matching vtbl entry.
https://github.com/dlang/dmd/pull/12302
Comment #6 by dlang-bot — 2021-04-09T10:48:53Z
dlang/dmd pull request #12408 "Merge stable into master" was merged into master:
- df37bc2c2f03180196ceccc64a4f653ad9807f0d by Puneet Goel:
Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <… (#12302)
* Fix issue 19192 - [wrong-code] [crashes] Covariant method interface <- abstract class <- class hierarchies
While analyzing covariant methods, dmd semantic analyzer searched for
immediate interfaces of the class that may have a vtbl entry matching
the method. This failed for possible scenarios where the covariant
method may be declared in an interface inheritance of an abstract base
class.
The fix adds a for loop that iterates over the base classes to find
the relevant interface with matching vtbl entry.
https://github.com/dlang/dmd/pull/12408