Bug 14083 – Remained unresolved forward reference issue with template classes
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-30T15:09:00Z
Last change time
2015-01-30T22:02:49Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-01-30T15:09:58Z
From: http://forum.dlang.org/thread/[email protected]
Following code should work, but doesn't.
import std.stdio;
class Base(T)
{
public void Foo(A!T a)
{
writeln("Base.Foo(A a)");
}
public void Foo(B!T a)
{
writeln("Base.Foo(B a)");
}
}
class A(T) : Base!T
{
public T v;
this(T v)
{
this.v = v;
}
}
class B(T) : Base!T
{
public override void Foo(A!T a)
{
writeln("A: ", a.v);
}
}
int main()
{
A!int a = new A!(int)(1);
B!int b = new B!(int)();
a.Foo(b);
b.Foo(a);
return 0;
}
Output:
test.d(16): Error: class test.A!int.A is forward referenced when looking for 'v'
test.d(16): Error: class test.A!int.A is forward referenced when looking for 'opDot'
test.d(16): Error: class test.A!int.A is forward referenced when looking for 'opDispatch'
test.d(29): Error: no property 'v' for type 'test.A!int.A'
test.d(10): Error: template instance test.B!int error instantiating
test.d(16): instantiated from here: Base!int
test.d(35): instantiated from here: A!int