www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13687] New: Virtual call in the interface's precondition is


          Issue ID: 13687
           Summary: Virtual call in the interface's precondition is
                    dispatched to the wrong vtbl entry
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: acehreli yahoo.com

If an interface makes a virtual function call in its precondition block then
the call gets dispatched to the wrong vtbl entry. (Probably to toHash() in the
following program).

For the bug to occur, the derived class must have a precondition block as well.

Also see the following discussion:

  http://forum.dlang.org/thread/m3bbbb$lgi$1 digitalmars.

import std.stdio;

interface I
    void foo()
        int result = virtualCall();

    int virtualCall();

class C : I
    void foo()

    int virtualCall()
        return 42;

void main()
    new C().foo();

The output of the program is not the expected 42 from virtualCall():



Nov 04 2014