D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2389 - void* vs. object type overloading fails for null giving bad error message
Summary: void* vs. object type overloading fails for null giving bad error message
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P3 normal
Assignee: Walter Bright
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2008-10-03 20:02 UTC by BCS
Modified: 2014-02-24 15:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description BCS 2008-10-03 20:02:26 UTC
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 Walter Bright 2008-10-04 00:56:16 UTC
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 Walter Bright 2008-10-04 01:03:23 UTC
I should add that this 'works' in D 2.0 because partial ordering is used to resolve overloading conflicts.
Comment 3 BCS 2008-10-04 14:56:18 UTC
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 BCS 2008-10-04 15:37:54 UTC
EDIT:

<-Just like the "invalid expressions are of type null" thing.
->Just like the "invalid expressions are of type int" thing.
Comment 5 Walter Bright 2012-05-05 02:27:38 UTC
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)