www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug when overload function in multiple modules?

reply "Lemonfiend" <lemon fie.nd> writes:
I get:
src\app.d(19): Error: None of the overloads of 'foo' are callable 
using argument types (C3), candidates are:
src\app.d(28):        main.foo(C1 c)
src\app.d(38):        main.foo(C2 c)

It does work when I explicitly import c3.foo.

--- file app.d
module app;

import std.stdio;

import c3;
//import c3:foo; //uncomment this and it works

void main()
{
	C1 c1 = new C1();
	c1.foo();
	writeln(c1.i);

	C2 c2 = new C2();
	c2.foo();
	writeln(c2.i);

	C3 c3 = new C3();
	c3.foo();
	writeln(c3.i);
}

class C1
{
	int i;
}

void foo(C1 c)
{
	c.i = 1;
}

class C2
{
	int i;
}

void foo(C2 c)
{
	c.i = 2;
}

--- file c3.d
module c3;

class C3
{
	int i;
}

void foo(C3 c)
{
	c.i = 3;
}
Aug 27 2014
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/27/2014 07:38 AM, Lemonfiend wrote:
 I get:
 src\app.d(19): Error: None of the overloads of 'foo' are callable using
 argument types (C3), candidates are:
 src\app.d(28):        main.foo(C1 c)
 src\app.d(38):        main.foo(C2 c)

 It does work when I explicitly import c3.foo.

 --- file app.d
 module app;

 import std.stdio;

 import c3;
 //import c3:foo; //uncomment this and it works
I think it is the protection against function hijacking: http://dlang.org/hijack.html Ali
Aug 27 2014