Bug 13687 – Virtual call in the interface's precondition is dispatched to the wrong vtbl entry
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-11-04T22:40:35Z
Last change time
2018-10-11T17:45:14Z
Assigned to
No Owner
Creator
Ali Cehreli
Comments
Comment #0 by acehreli — 2014-11-04T22:40:35Z
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()
in
{
int result = virtualCall();
writeln(result);
}
int virtualCall();
}
class C : I
{
void foo()
in
{}
body
{}
int virtualCall()
{
return 42;
}
}
void main()
{
new C().foo();
}
The output of the program is not the expected 42 from virtualCall():
-226009216
Ali
Comment #1 by n8sh.secondary — 2018-10-10T22:35:03Z
Tested with DMD 2.082.0. Program output was "42" as desired.