Static method conflicts with non-static method?

Jacob Carlborg doob at me.com
Fri Apr 27 07:54:01 PDT 2012


On 2012-04-27 07:07, H. S. Teoh wrote:
> Is this a bug? Code:
>
> 	import std.stdio;
>
> 	struct S {
> 		static int func(int x) { return x+1; }
> 		int func(int x) { return x+2; }
> 	}
>
> 	void main() {
> 		S s;
> 		writeln(s.func(1));
> 	}
>
> DMD (latest git) output:
>
> 	test.d(10): Error: function test.S.func called with argument types:
> 		((int))
> 	matches both:
> 		test.S.func(int x)
> 	and:
> 		test.S.func(int x)
>
> The error message is unhelpful, but basically the complaint is that the
> static method is conflicting with the non-static method.
>
> But I would've thought it is unambiguous; I'd expect that s.func should
> resolve to the non-static method, and S.func to the static method. After
> all, no object is needed to invoke the static method, and the static
> method cannot be invoked without an object.

It's intended behavior but there's a suggestion to change that: 
http://d.puremagic.com/issues/show_bug.cgi?id=3345

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list