Skip to content

Commit 96b1b83

Browse files
committed
Strip synthetic ascriptions from inlined calls
1 parent 473246e commit 96b1b83

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,16 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
831831
}
832832
}
833833

834+
/** Strip `Typed` nodes, recursing into `Block` nodes. */
835+
def stripSyntheticTyped(tree: Tree)(using Context): Tree =
836+
unsplice(tree) match
837+
case Typed(expr, _) if tree.span.isSynthetic =>
838+
stripSyntheticTyped(expr)
839+
case Block(stats, expr) =>
840+
cpy.Block(tree)(stats, stripSyntheticTyped(expr))
841+
case _ =>
842+
tree
843+
834844
/** The type and term arguments of a possibly curried call, in the order they are given */
835845
def allArgss(tree: Tree): List[List[Tree]] =
836846
@tailrec

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ class Inliner(val call: tpd.Tree)(using Context):
790790
}
791791

792792
// Run a typing pass over the inlined tree. See InlineTyper for details.
793-
val expansion1 = inlineTyper.typed(expansion)(using inlineCtx)
793+
val expansion1 = inlineTyper.typed(stripSyntheticTyped(expansion))(using inlineCtx)
794794

795795
if (ctx.settings.verbose.value) {
796796
inlining.println(i"to inline = $rhsToInline")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
inline def f(): Long =
2+
1L
3+
4+
inline def g(): Long =
5+
inline val x = f()
6+
x
7+
8+
inline def h(): Long =
9+
inline if g() > 0L then 1L else 0L
10+
11+
@main def Test: Unit =
12+
println(h())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
transparent inline def f(): Long =
2+
1L
3+
4+
transparent inline def g(): Long =
5+
inline val x = f()
6+
x
7+
8+
transparent inline def h(): Long =
9+
inline if g() > 0L then 1L else 0L
10+
11+
@main def Test: Unit =
12+
println(h())

0 commit comments

Comments
 (0)