Bug 14916 – opDispatch: no property error for parameter type mismatch

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-13T13:04:19Z
Last change time
2022-10-10T06:54:10Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Luís Marques

Comments

Comment #0 by luis — 2015-08-13T13:04:19Z
unittest // getter is fine { struct S { auto opDispatch(string name)() { return 42; } } S s; s.foo; } unittest // setter is fine { struct S { void opDispatch(string name)(ushort value) { } } S s; s.foo = 42; // fine long x = 42; s.foo = x; // correct error: "not callable using argument types (long)" } unittest // getter and setter... bug: misleading error { struct S { auto opDispatch(string name)() { return 42; } void opDispatch(string name)(ushort value) { } } S s; s.foo = 42; // fine long x = 42; s.foo = x; // *wrong* error: "no property 'foo' for type 'S'" }
Comment #1 by ozan.nurettin.sueel — 2015-09-17T07:41:38Z
OpDispatch is a important functionality to bring state-of-the-art language flexibility.
Comment #2 by TeddyBear12311 — 2018-06-29T13:24:49Z
Same problem. I wanted to provide key to field emulation and nothing works correctly consistently. I have override various op's such as opCall and opDispatch and they all are not called when the property is used. The code has worked in the past but i changed a few internal things not related to the opDispatch and then it started failing again. The error is test.d: Error: no property `y` for type `X` where X implements opDispatch but which is never called for x.y.
Comment #3 by razvan.nitu1305 — 2022-10-10T06:53:36Z
The problem is that we now have 2 overloads and none match, therefore the compiler simply goes with a generic error message "no property foo for s". This is the correct behavior since the compiler does not have sufficient information to distinguish which overload is less wrong. However, the compiler now additionally provides: onlineapp.d(51): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message. `opDispatch` is pretty much a black whole that eats up everything, therefore it is close to impossible to find a logic that gives the best error message in each situation. That is why this alternative was preferred. I will close this as WONTFIX
Comment #4 by razvan.nitu1305 — 2022-10-10T06:54:10Z
Actually, WORKSFORME is a better category.