Bug 409 – function resolving with global function if member matches

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-10-08T13:40:00Z
Last change time
2014-02-15T13:21:04Z
Keywords
diagnostic
Assigned to
bugzilla
Creator
benoit

Comments

Comment #0 by benoit — 2006-10-08T13:40:57Z
bool equals( char[] a, char[] b ){ return a==b; } class A{ bool equals( A other ){ return this is A; } void func(){ char[] a1 = "a"; a1.equals( "b"[] ); // line 11 } } I get this error: t.d(11): function t.A.equals (A) does not match argument types (char[],char[]) t.d(11): Error: expected 1 arguments, not 2 t.d(11): cannot implicitly convert expression (a1) of type char[] to t.A
Comment #1 by smjg — 2006-10-08T19:50:01Z
There is in fact no match. But the error message is indeed confusing.
Comment #2 by benoit — 2006-10-08T20:14:02Z
(In reply to comment #1) > There is in fact no match. But the error message is indeed confusing. > I wonder because it compiles without the method A.equals
Comment #3 by bugzilla — 2006-10-16T04:27:14Z
It's working as designed. a1.equals("b"[]) is first rewritten as equals(a1,"b"[]), because a1 is an array. Then, "equals" is looked for in the enclosing scopes. The first one found is A.equals. The arguments are (a1,"b"[]) which are types (char[],char[]), which do not match (A), the argument types for A.equals. Hence the error message. If A.equals is removed, then the global equals is found, which does match the argument types. Not a bug.