Skip to content

Commit b3bbae5

Browse files
committed
Merge pull request #137 from yebblies/issue4511
Issue 4511 - Covariance problem
2 parents 772ff9a + 532e273 commit b3bbae5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/statement.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,6 +3634,8 @@ Statement *ReturnStatement::semantic(Scope *sc)
36343634
exp = exp->castTo(sc, exp->type->invariantOf());
36353635
}
36363636

3637+
if (fd->tintro)
3638+
exp = exp->implicitCastTo(sc, fd->type->nextOf());
36373639
exp = exp->implicitCastTo(sc, tret);
36383640
if (!((TypeFunction *)fd->type)->isref)
36393641
exp = exp->optimize(WANTvalue);

test/fail_compilation/fail4511.d

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void test72()
2+
{
3+
class A {}
4+
class B : A {}
5+
6+
class X
7+
{
8+
abstract A func();
9+
}
10+
class Y : X
11+
{
12+
B func() { return new A(); }
13+
}
14+
}
15+
16+
void main() {}

0 commit comments

Comments
 (0)