Bug 9777 – Calling final interface method leads to wrong code

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-21T08:21:00Z
Last change time
2015-06-09T05:10:40Z
Keywords
wrong-code
Assigned to
nobody
Creator
johannespfau

Comments

Comment #0 by johannespfau — 2013-03-21T08:21:43Z
Test case: ---- import core.stdc.stdio; interface Timer { final int run() { printf("Timer.run()\n"); fun(); return 1; }; int fun(); } interface Application { final int run() { printf("Application.run()\n"); fun(); return 2; }; int fun(); } class TimedApp : Timer, Application { int fun() { printf("TimedApp.fun()\n"); return 0; } } void main() { auto app = new TimedApp; (cast(Application)app).run(); (cast(Timer)app).run(); app.Application.run(); //fun not called app.Timer.run(); //fun not called } --- Note how "TimedApp.fun()" is not called when using app.Interface.fun. The reason is that the wrong this pointer is passed to the interface functions. For more information see http://forum.dlang.org/post/[email protected]
Comment #1 by johannespfau — 2013-03-21T08:29:24Z
Comment #2 by github-bugzilla — 2013-03-21T22:35:49Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f35c753d3d34f14473ec34570a0693ee00f805f0 Fix issue 9777 Wrong code when calling final interface methods Can't use DotTypeExp when converting to the interface as the pointer needs to be adjusted. Use CastExp instead. https://github.com/D-Programming-Language/dmd/commit/1375dee59cdc795ce489985ece034fbbc75f353e Merge pull request #1781 from jpf91/fix9777 Fix issue 9777 Wrong code when calling final interface methods