Thread overview
[Issue 19192] DMD generates invalid code for covariants involving template classes
Aug 27, 2018
ag0aep6g
[Issue 19192] DMD generates invalid code for covariants for some interface <- abstract class <- class hierarchies
Aug 28, 2018
Puneet Goel
[Issue 19192] [ICE] [wrong-code] for some interface <- abstract class <- class hierarchies
Sep 28, 2018
Nicholas Wilson
[Issue 19192] [wrong-code] [crashes] for some interface <- abstract class <- class hierarchies
Sep 28, 2018
Nicholas Wilson
Sep 28, 2018
Nicholas Wilson
[Issue 19192] [wrong-code] [crashes] Covariant method interface <- abstract class <- class hierarchies
Mar 24, 2021
Puneet Goel
Mar 24, 2021
Dlang Bot
Mar 24, 2021
Dlang Bot
Apr 09, 2021
Dlang Bot
August 27, 2018
https://issues.dlang.org/show_bug.cgi?id=19192

ag0aep6g <ag0aep6g@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |ag0aep6g@gmail.com

--- Comment #1 from ag0aep6g <ag0aep6g@gmail.com> ---
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. */
}
----

--
August 28, 2018
https://issues.dlang.org/show_bug.cgi?id=19192

Puneet Goel <puneet@coverify.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|DMD generates invalid code  |DMD generates invalid code
                   |for covariants involving    |for covariants for some
                   |template classes            |interface <- abstract class
                   |                            |<- class hierarchies

--
September 28, 2018
https://issues.dlang.org/show_bug.cgi?id=19192

Nicholas Wilson <iamthewilsonator@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice
                 CC|                            |iamthewilsonator@hotmail.co
                   |                            |m
            Summary|DMD generates invalid code  |[ICE] [wrong-code] for some
                   |for covariants for some     |interface <- abstract class
                   |interface <- abstract class |<- class hierarchies
                   |<- class hierarchies        |

--- Comment #2 from Nicholas Wilson <iamthewilsonator@hotmail.com> ---
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

--
September 28, 2018
https://issues.dlang.org/show_bug.cgi?id=19192

Nicholas Wilson <iamthewilsonator@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice                         |
            Summary|[ICE] [wrong-code] for some |[wrong-code] [crashes] for
                   |interface <- abstract class |some interface <- abstract
                   |<- class hierarchies        |class <- class hierarchies

--
September 28, 2018
https://issues.dlang.org/show_bug.cgi?id=19192

--- Comment #3 from Nicholas Wilson <iamthewilsonator@hotmail.com> ---
Sorry that segfaults not ICE's

--
March 24, 2021
https://issues.dlang.org/show_bug.cgi?id=19192

Puneet Goel <puneet@coverify.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[wrong-code] [crashes] for  |[wrong-code] [crashes]
                   |some interface <- abstract  |Covariant method interface
                   |class <- class hierarchies  |<- abstract class <- class
                   |                            |hierarchies

--
March 24, 2021
https://issues.dlang.org/show_bug.cgi?id=19192

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
March 24, 2021
https://issues.dlang.org/show_bug.cgi?id=19192

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--
April 09, 2021
https://issues.dlang.org/show_bug.cgi?id=19192

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--