[Issue 19232] New: Compiler bug when override function with template this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 7 12:27:24 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19232

          Issue ID: 19232
           Summary: Compiler bug when override function with template this
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: riddlermichael at gmail.com

Consider this code:

---
class Unknown;

abstract class Foo(T : Unknown) {
        Object get(this D)() {
                return (cast(D) this).get();
        }
}

class Foo(T) : Foo!Unknown {
        T t;

        this() {
        }

        this(T t) {
                this.t = t;
        }

        override T get() {
                return t;
        }

        void set(T t) {
                this.t = t;
        }
}

void main() {
        auto foo = new Foo!Object();
        Foo!Unknown afoo = foo;
        auto t = afoo.get();
}
---

It crashes:

---
DMD v2.082.0-beta.1

predefs   DigitalMars Windows LittleEndian D_Version2 all D_InlineAsm
D_InlineAsm_X86 X86 Win32 CRuntime_DigitalMars assert D_ModuleInfo D_Exceptions
D_TypeInfo D_HardFloat
binary    C:\D\dmd2\windows\bin\dmd.exe
version   v2.082.0-beta.1

config    C:\D\dmd2\windows\bin\sc.ini
DFLAGS    -IC:\D\dmd2\windows\bin\..\..\src\phobos
-IC:\D\dmd2\windows\bin\..\..\src\druntime\import
---

object.Error@(0): Access Violation

Without `override` in Foo!T.get it works, but leads to infinite recursion calls
of Foo!Unknown.get. Is it just a compiler bug, or it shouldn't work in anyway?

--


More information about the Digitalmars-d-bugs mailing list