Skip to content

Commit 35d0acd

Browse files
committed
Add fullyDefinedType for class parent types
If we do not do that, any type variables in the parent type get interpolated later, when the whole primary constructor is typed. But by then we miss the context of what their variance was.
1 parent 9917029 commit 35d0acd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ class Namer { typer: Typer =>
843843
val targs1 = targs map (typedAheadType(_))
844844
val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes
845845
if (ptype.typeParams.isEmpty) ptype
846-
else typedAheadExpr(parent).tpe
846+
else fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.pos)
847847
}
848848

849849
/* Check parent type tree `parent` for the following well-formedness conditions:

tests/pos/i2218.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Rule[In]
2+
3+
class C {
4+
def ruleWithName[In](f: In => Int): Rule[In] = {
5+
new DefaultRule(f) {}
6+
}
7+
8+
class DefaultRule[In](f: In => Int) extends Rule[In]
9+
}

0 commit comments

Comments
 (0)