[Issue 16459] New: opDispatch gives obtuse error when dispatching to a function that doesn't exist
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Sep 1 07:04:36 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16459
Issue ID: 16459
Summary: opDispatch gives obtuse error when dispatching to a
function that doesn't exist
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: gooberman at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list