Skip to content

Commit

Permalink
fix Issue 8221 - typeof(null) rejected as return type for covariant o…
Browse files Browse the repository at this point in the history
…verrides
  • Loading branch information
9rnsr committed Jun 12, 2012
1 parent 8fa7bdd commit bc55af9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mtype.c
Expand Up @@ -5132,6 +5132,8 @@ int Type::covariant(Type *t, StorageClass *pstc)
}
else if (t1n->ty == t2n->ty && t1n->implicitConvTo(t2n))
goto Lcovariant;
else if (t1n->ty == Tnull && t1n->implicitConvTo(t2n))
goto Lcovariant;
}
goto Lnotcovariant;

Expand Down
22 changes: 22 additions & 0 deletions test/runnable/nulltype.d
Expand Up @@ -95,13 +95,35 @@ void test7278()
Foo7278!null b;
}

/**********************************************/
// 8221

class A8221
{
A8221 foo() { return this; }
}
class B8221: A8221
{
override typeof(null) foo() { return null; } // error
}
void test8221()
{
auto a = new A8221();
assert(a.foo() is a);
auto b = new B8221();
assert(b.foo() is null);
a = b;
assert(a.foo() is null);
}

/**********************************************/

int main()
{
test1();
test2();
test7278();
test8221();

printf("Success\n");
return 0;
Expand Down

0 comments on commit bc55af9

Please sign in to comment.