Skip to content

Skipping inlined tree reduction of type member selection #13578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =>
Expand Down
17 changes: 11 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i13503.scala
Original file line number Diff line number Diff line change
@@ -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]