Bug 2389 – void* vs. object type overloading fails for null giving bad error message
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2008-10-03T20:02:00Z
Last change time
2014-02-24T15:32:17Z
Keywords
diagnostic
Assigned to
bugzilla
Creator
shro8822
Comments
Comment #0 by shro8822 — 2008-10-03T20:02:26Z
one option is an exact match but it still fails? (adding a cast to void* fixes it)
class C
{
void opIndexAssign(void*,int){}
void opIndexAssign(C,int){}
}
void main()
{
C c = new C;
c[0] = null;
}
Error:
Line 10: function C.opIndexAssign called with argument types:
(void*,int)
matches both:
C.opIndexAssign(void*,int)
and:
C.opIndexAssign(C,int)
Comment #1 by bugzilla — 2008-10-04T00:56:16Z
null is not a simple void* like it is in C. It exact matches several different types, including objects and void*. Hence the ambiguity.
Comment #2 by bugzilla — 2008-10-04T01:03:23Z
I should add that this 'works' in D 2.0 because partial ordering is used to resolve overloading conflicts.
Comment #3 by shro8822 — 2008-10-04T14:56:18Z
The error message leave a lot to be desired.
Re-opening at low priority as a diagnostic bug.
It should be fixed "sooner or later" even if it requiters tweaking the type system. Just like the "invalid expressions are of type null" thing.
Comment #4 by shro8822 — 2008-10-04T15:37:54Z
EDIT:
<-Just like the "invalid expressions are of type null" thing.
->Just like the "invalid expressions are of type int" thing.
Comment #5 by bugzilla — 2012-05-05T02:27:38Z
Now produces:
foo.d(10): Error: function foo.C.opIndexAssign called with argument types:
((typeof(null),int))
matches both:
foo.C.opIndexAssign(void* _param_0, int _param_1)
and:
foo.C.opIndexAssign(C _param_0, int _param_1)