Bug 20561 – Compiler silently ignores override on templated method if interface/base class defines it

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2020-02-05T04:32:04Z
Last change time
2024-12-13T19:07:01Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: dmd#17937 →

Comments

Comment #0 by pro.mathias.lang — 2020-02-05T04:32:04Z
Code example: ``` class Channel (T) {} interface Scheduler { void spawn (T) (Channel!T chan); } class ThreadScheduler : Scheduler { override void spawn (T) (Channel!T chan) { } } void main () { Scheduler ths = new ThreadScheduler; ths.spawn(new Channel!int); } ``` This will lead to a link error with DMD 2.090.0: ``` Undefined symbols for architecture x86_64: "__D3bug9Scheduler__T5spawnTiZQjMFCQBf__T7ChannelTiZQlZv", referenced from: __Dmain in bug.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Error: linker exited with status 1 ``` There are several problem here: 1) Having a templated method declaration without definition in an interface is odd. There can be a use case, e.g. for `extern` declarations, but those are marked as `extern`. But that's still open to discussion. 2) However, the `override void spawn` is completely wrong: the compiler should give the usual "Cannot override non-virtual method" error. Another example: ``` class Channel (T) {} interface Scheduler { void spawn (T) (Channel!T chan) { assert(0); } } class ThreadScheduler : Scheduler { override void spawn (T) (Channel!T chan) { } } void main () { Scheduler ths = new ThreadScheduler; ths.spawn(new Channel!int); } ``` This triggers the assertion, because `Scheduler.spawn` is called (as it should), however users would expect `ThreadScheduler.spawn` to be called.
Comment #1 by robert.schadek — 2024-12-13T19:07:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17937 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB