Skip to content

Commit dc9e2c7

Browse files
Merge pull request #13578 from soronpo/fix_13503_attempt2
Skipping inlined tree reduction of type member selection
2 parents 1dda803 + 7e7f350 commit dc9e2c7

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
@@ -1514,13 +1514,18 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
15141514
assert(tree.hasType, tree)
15151515
val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this))
15161516
val resNoReduce = untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)
1517-
val resMaybeReduced = constToLiteral(reducer.reduceProjection(resNoReduce))
1518-
if (resNoReduce ne resMaybeReduced)
1519-
typed(resMaybeReduced, pt) // redo typecheck if reduction changed something
1517+
val reducedProjection = reducer.reduceProjection(resNoReduce)
1518+
if reducedProjection.isType then
1519+
//if the projection leads to a typed tree then we stop reduction
1520+
resNoReduce
15201521
else
1521-
val res = resMaybeReduced
1522-
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
1523-
inlineIfNeeded(res)
1522+
val resMaybeReduced = constToLiteral(reducedProjection)
1523+
if resNoReduce ne resMaybeReduced then
1524+
typed(resMaybeReduced, pt) // redo typecheck if reduction changed something
1525+
else
1526+
val res = resMaybeReduced
1527+
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
1528+
inlineIfNeeded(res)
15241529
}
15251530

15261531
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)