Skip to content

Commit 4c8ed6b

Browse files
committed
Move stripping of ascriptions from PrepareInlineable.wrapRHS to InlineTyper.typedTyped
1 parent 1163435 commit 4c8ed6b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,19 @@ class Inliner(val call: tpd.Tree)(using Context):
10471047
reduceInlineMatchExpr(sel)
10481048
}
10491049

1050+
private def shouldStripAscription(tree: Typed)(using Context): Boolean =
1051+
val exprTp = tree.expr.tpe
1052+
tree.hasAttachment(PrepareInlineable.InlineResultAscription)
1053+
&& exprTp.exists
1054+
&& !exprTp.widen.isRef(defn.NothingClass)
1055+
&& !exprTp.widen.isRef(defn.NullClass)
1056+
&& (exprTp frozen_<:< tree.tpe)
1057+
1058+
override def typedTyped(tree: untpd.Typed, pt: Type)(using Context): Tree =
1059+
super.typedTyped(tree, pt) match
1060+
case typedTree: Typed if shouldStripAscription(typedTree) => typedTree.expr
1061+
case typedTree => typedTree
1062+
10501063
override def newLikeThis(nestingLevel: Int): Typer = new InlineTyper(initialErrorCount, nestingLevel)
10511064

10521065
/** True if this inline typer has already issued errors */
@@ -1056,20 +1069,8 @@ class Inliner(val call: tpd.Tree)(using Context):
10561069
val meth = tree.symbol
10571070
if meth.isAllOf(DeferredInline) then
10581071
errorTree(tree, em"Deferred inline ${meth.showLocated} cannot be invoked")
1059-
else if Inlines.needsInlining(tree) then
1060-
StripInlineResultAscriptionMap().transform(Inlines.inlineCall(simplify(tree, pt, locked)))
1061-
else
1062-
tree
1063-
1064-
private class StripInlineResultAscriptionMap extends tpd.TreeMap:
1065-
override def transform(tree: Tree)(using Context): Tree =
1066-
tree match
1067-
case Typed(expr, _) if tree.hasAttachment(PrepareInlineable.InlineResultAscription) =>
1068-
expr
1069-
case tree: Inlined =>
1070-
super.transform(tree)
1071-
case _ =>
1072-
tree
1072+
else if Inlines.needsInlining(tree) then Inlines.inlineCall(simplify(tree, pt, locked))
1073+
else tree
10731074

10741075
override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
10751076
super.typedUnadapted(tree, pt, locked) match

0 commit comments

Comments
 (0)