An example of weird template error messaging
ag0aep6g
anonymous at example.com
Sun Aug 4 20:58:27 UTC 2019
On 04.08.19 17:18, Ethan wrote:
> ----------
>
> template ApplyRight( alias Template, Right... )
> {
> alias ApplyRight( Left... ) = Template!( Left, Right );
> }
>
> struct ObjectRefImpl( Type, BaseType ) if( is( Type Super == super ) &&
> is( Super == BaseType ) )
> {
> Type refval;
> }
>
> alias ObjRef = ApplyRight!( ObjectRefImpl, ObjectBase );
>
> class ObjectBase
> {
> string name;
> }
>
> alias ObjectOne = ObjRef!ObjectOneImpl;
>
> class ObjectOneImpl : ObjectBase
> {
> ObjectTwo two;
> }
>
> alias ObjectTwo = ObjRef!ObjectTwoImpl;
>
> class ObjectTwoImpl : ObjectBase
> {
> ObjectOne one;
> }
>
> void main()
> {
> import std.stdio : writeln;
>
> ObjectOne one = { new ObjectOneImpl() };
> writeln( "Oh hi Mark" );
> }
>
Reduced further:
----
struct ObjectRefImpl1() if (is(ObjectOneImpl Super == super)) {}
struct ObjectRefImpl2() if (is(ObjectTwoImpl Super == super)) {}
alias ObjectOne = ObjectRefImpl1!();
class ObjectOneImpl
{
alias Two = ObjectRefImpl2!();
}
class ObjectTwoImpl
{
ObjectOne one; /* Error: template instance `test.ObjectRefImpl1!()`
is used as a type */
}
----
Compilation succeeds if `ObjectOne` is moved below `ObjectOneImpl`.
More information about the Digitalmars-d
mailing list