Bug 16459 – opDispatch gives obtuse error when dispatching to a function that doesn't exist

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-01T14:04:36Z
Last change time
2022-11-10T13:39:56Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Ethan Watson

Comments

Comment #0 by gooberman — 2016-09-01T14:04:36Z
struct SomeObject( T ) { auto opDispatch( string op, Args... )( Args args ) { mixin( "return pObject." ~ op ~ "( args );" ); } T* pObject; } Depending on how you invoke opDispatch, it either gives you a helpful error message or one that has you scratching your head. For example: someObject.doSomething(); Gives the error message: test.d: Error: no property 'doSomething' for type 'SomeObject!(Something)' But: someObject.opDispatch!"doSomething"(); Gives the error: test.d-mixin: Error: no property 'doSomething' for type 'Something*' The problem here is that the opDispatch has been invoked because it can't find the property in the first place. If the code inside the opDispatch fails to compile, I want to know about it. The semantic difference here is that invoking opDispatch manually is explicitly telling exactly me where the problem is, whereas invoking it naturally is telling me something I already know.
Comment #1 by razvan.nitu1305 — 2022-11-10T13:39:56Z
This seems to have been improved now. In the first case it gives: test.d(14): Error: no property `doSomething` for `someObject` of type `test.SomeObject!int` test.d(14): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message So, at least it gives you a hint that this may be the problem. The idea is that currently the compiler cannot know if the error comes from passing the wrong arguments to opDispatch or if the error comes from within the innards of opDispatch that is why it just asks the user to call opDispatch explicitly. I think that until we find a way to deal with opDispatch this should be enough.