Bug 21184 – Unimplemented methods of interface are not reported as errors during compilation.

Status
RESOLVED
Resolution
INVALID
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-21T13:37:30Z
Last change time
2022-07-27T09:37:17Z
Assigned to
No Owner
Creator
alexandru.ermicioi

Comments

Comment #0 by alexandru.ermicioi — 2020-08-21T13:37:30Z
Example: -------- import std; interface Promise { int doIt(); } class Silly { int doIt(); } void main() { return new Silly().doIt(); } -------- Expected: To have a compiler error telling us that doIt is not implemented. Actual: Compiler happily accepts this, then fails at link time, with error about missing implementation.
Comment #1 by razvan.nitu1305 — 2020-09-17T07:48:11Z
I think that this is the correct behavior. The function is defined (and therefore respects the interface contract) it's just that it does not have a body. You can provide the body in a different file. Think about header files (.di). Those should contain compilable d code and not contain any function bodies. If this were to be fixed, then you would not be able to have any interfaces and classes in .di files. Closing as invalid.
Comment #2 by alexandru.ermicioi — 2020-09-17T10:46:47Z
This is in .d file, and is completely clear that is a bug, since you can't have an unimplemented method. Only abstract methods may not have a body, since it is expected to be implemented somewhere else. I struggle to even understand how you could implement such a method given it is a D method, not c++ one.
Comment #3 by alexandru.ermicioi — 2020-09-17T11:00:19Z
Reopening it.
Comment #4 by razvan.nitu1305 — 2020-09-18T02:27:05Z
(In reply to alexandru.ermicioi from comment #2) > This is in .d file, and is completely clear that is a bug, since you can't > have an unimplemented method. Only abstract methods may not have a body, > since it is expected to be implemented somewhere else. > > I struggle to even understand how you could implement such a method given it > is a D method, not c++ one. If you know the exact mangled name you can implement it in a different file
Comment #5 by razvan.nitu1305 — 2020-09-18T02:34:43Z
Also, there in the initial example you forgot to inherit from Promise.
Comment #6 by dkorpel — 2022-07-25T15:24:15Z
(In reply to alexandru.ermicioi from comment #2) > This is in .d file, and is completely clear that is a bug, since you can't > have an unimplemented method. (...) I struggle to even understand how you > could implement such a method given it is a D method, not c++ one. That's just false. Separate compilation is a thing, and functions without bodies are not limited to `.di` files (which is just a convention) or `extern(C++)` (which is just a different ABI and mangling scheme). See: https://dlang.org/spec/function.html#function-declarations
Comment #7 by alexandru.ermicioi — 2022-07-25T17:31:12Z
Well, at that point I've failed to think about separate compilation. Seems like forward declarations are allowed anywhere. It is still an unpleasant experience when you forget implementing a method and get mangled method name as an error from linker and not compiler.
Comment #8 by dkorpel — 2022-07-27T09:37:17Z
(In reply to alexandru.ermicioi from comment #7) > It is still an unpleasant experience when you forget implementing a method > and get mangled method name as an error from linker and not compiler. Yes, it would be great to have linkers with D demangling support.