Skip to content

Commit bef88b6

Browse files
committed
Skipping inlined tree reduction of type member selection
1 parent fa40f4e commit bef88b6

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
569569
* This avoids the situation where we have a Select node that does not have a symbol.
570570
*/
571571
def constToLiteral(tree: Tree)(using Context): Tree = {
572+
assert(!tree.isType)
572573
val tree1 = ConstFold(tree)
573574
tree1.tpe.widenTermRefExpr.dealias.normalized match {
574575
case ConstantType(Constant(_: Type)) if tree.isInstanceOf[Block] =>

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,13 +1504,18 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
15041504
assert(tree.hasType, tree)
15051505
val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
15061506
val resNoReduce = untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)
1507-
val resMaybeReduced = constToLiteral(reducer.reduceProjection(resNoReduce))
1508-
if (resNoReduce ne resMaybeReduced)
1509-
typed(resMaybeReduced, pt) // redo typecheck if reduction changed something
1507+
val reducedProjection = reducer.reduceProjection(resNoReduce)
1508+
if (reducedProjection.isType)
1509+
//in case the projection leads to a typed tree, then there is nothing to reduce
1510+
resNoReduce
15101511
else
1511-
val res = resMaybeReduced
1512-
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
1513-
inlineIfNeeded(res)
1512+
val resMaybeReduced = constToLiteral(reducedProjection)
1513+
if (resNoReduce ne resMaybeReduced)
1514+
typed(resMaybeReduced, pt) // redo typecheck if reduction changed something
1515+
else
1516+
val res = resMaybeReduced
1517+
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
1518+
inlineIfNeeded(res)
15141519
}
15151520

15161521
override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree =

tests/pos/i13503.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait First {type Out}
2+
given First with {type Out = 123}
3+
4+
trait Second {type Out}
5+
transparent inline given (using f: First): Second = new Second {type Out = f.Out}
6+
7+
val s = summon[Second]
8+
val x = summon[s.Out =:= 123]

0 commit comments

Comments
 (0)