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)
null is not a simple void* like it is in C. It exact matches several different types, including objects and void*. Hence the ambiguity.
I should add that this 'works' in D 2.0 because partial ordering is used to resolve overloading conflicts.
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.
EDIT: <-Just like the "invalid expressions are of type null" thing. ->Just like the "invalid expressions are of type int" thing.
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)