Skip to content

Commit b0a59de

Browse files
committed
Fix #6213: Convert RefinedTypeTrees to TypeTrees in ReTyper
The standard treatment of RefinedTypeTrees creates a class definition, typechecks it and then extracts the type from that. The class definition does not form part of the resulting tree. This treatment is not workable for ReTyper since ReTyper is not prepared to typecheck fresh class definitions from scratch. We avoid the problem by having ReTyper convert the RefinedTypeTree to a TypeTree instead, keeping just the type. Note: The only reason why Typer does not do the same thing is so that we can keep the refinements as trees for IDE navigation. But that's not necessary for trees that have undergone a ReTyper step (i.e. typically inlined trees).
1 parent 7143421 commit b0a59de

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class ReTyper extends Typer with ReChecking {
6565
override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree =
6666
promote(tree)
6767

68+
override def typedRefinedTypeTree(tree: untpd.RefinedTypeTree)(implicit ctx: Context): TypTree =
69+
promote(TypeTree(tree.tpe).withSpan(tree.span))
70+
6871
override def typedFunPart(fn: untpd.Tree, pt: Type)(implicit ctx: Context): Tree =
6972
typedExpr(fn, pt)
7073

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ class Typer extends Namer
12731273
assignType(cpy.SingletonTypeTree(tree)(ref1), ref1)
12741274
}
12751275

1276-
def typedRefinedTypeTree(tree: untpd.RefinedTypeTree)(implicit ctx: Context): RefinedTypeTree = track("typedRefinedTypeTree") {
1276+
def typedRefinedTypeTree(tree: untpd.RefinedTypeTree)(implicit ctx: Context): TypTree = track("typedRefinedTypeTree") {
12771277
val tpt1 = if (tree.tpt.isEmpty) TypeTree(defn.ObjectType) else typedAheadType(tree.tpt)
12781278
val refineClsDef = desugar.refinedTypeToClass(tpt1, tree.refinements).withSpan(tree.span)
12791279
val refineCls = createSymbol(refineClsDef).asClass

tests/pos/i6213.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
class C { type T }
3+
inline def foo[U] <: Any = (??? : C { type T = U })
4+
5+
foo[Int]
6+
}

0 commit comments

Comments
 (0)