diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index b53c30e11d48..8592b6d2e647 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -569,6 +569,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => * This avoids the situation where we have a Select node that does not have a symbol. */ def constToLiteral(tree: Tree)(using Context): Tree = { + assert(!tree.isType) val tree1 = ConstFold(tree) tree1.tpe.widenTermRefExpr.dealias.normalized match { case ConstantType(Constant(_: Type)) if tree.isInstanceOf[Block] => diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 4895da94c56c..95c40584aeb0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1504,13 +1504,18 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { assert(tree.hasType, tree) val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this)) val resNoReduce = untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt) - val resMaybeReduced = constToLiteral(reducer.reduceProjection(resNoReduce)) - if (resNoReduce ne resMaybeReduced) - typed(resMaybeReduced, pt) // redo typecheck if reduction changed something + val reducedProjection = reducer.reduceProjection(resNoReduce) + if reducedProjection.isType then + //if the projection leads to a typed tree then we stop reduction + resNoReduce else - val res = resMaybeReduced - ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos) - inlineIfNeeded(res) + val resMaybeReduced = constToLiteral(reducedProjection) + if resNoReduce ne resMaybeReduced then + typed(resMaybeReduced, pt) // redo typecheck if reduction changed something + else + val res = resMaybeReduced + ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos) + inlineIfNeeded(res) } override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree = diff --git a/tests/pos/i13503.scala b/tests/pos/i13503.scala new file mode 100644 index 000000000000..c60b0e05862c --- /dev/null +++ b/tests/pos/i13503.scala @@ -0,0 +1,8 @@ +trait First {type Out} +given First with {type Out = 123} + +trait Second {type Out} +transparent inline given (using f: First): Second = new Second {type Out = f.Out} + +val s = summon[Second] +val x = summon[s.Out =:= 123] \ No newline at end of file