class is forward referenced when looking for 'v'
Kenji Hara via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 30 07:10:58 PST 2015
On Friday, 30 January 2015 at 00:09:17 UTC, Amber Thralll wrote:
> And the errors dmd returns:
> 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
>
> Is this a bug in D? Or am I doing something wrong?
In D, forward reference resolution should have consistent result
for template classes and non-template ones. If the code is
rewritten to non-template version:
import std.stdio;
class Base
{
public void Foo(A a)
{
writeln("Base.Foo(A a)");
}
public void Foo(B a)
{
writeln("Base.Foo(B a)");
}
};
class A : Base
{
public int v;
this(int v)
{
this.v = v;
}
}
class B : Base
{
public override void Foo(A a)
{
writeln("A: ", a.v);
}
}
int main()
{
A a = new A(1);
B b = new B();
a.Foo(b);
b.Foo(a);
return 0;
}
Compiler properly resolves forward references. Therefore, it's
definitely a compiler bug, and the template version should be
accepted.
I filed the issue in bugzilla:
https://issues.dlang.org/show_bug.cgi?id=14083
And will open a new pull request to fix compiler.
Kenji Hara
More information about the Digitalmars-d-learn
mailing list