Skip to content

Commit e0b3160

Browse files
committed
Fix #8842: Refine types of inlined inline vals
1 parent 0a62671 commit e0b3160

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12191219
super.typedIf(if1, pt)
12201220
}
12211221

1222+
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =
1223+
val vdef1 =
1224+
if sym.is(Inline) then
1225+
val rhs = typed(vdef.rhs)
1226+
sym.info = rhs.tpe
1227+
untpd.cpy.ValDef(vdef)(vdef.name, untpd.TypedSplice(TypeTree(rhs.tpe)), untpd.TypedSplice(rhs))
1228+
else vdef
1229+
super.typedValDef(vdef1, sym)
1230+
12221231
override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree =
12231232
constToLiteral(betaReduce(super.typedApply(tree, pt))) match {
12241233
case res: Apply if res.symbol == defn.InternalQuoted_exprSplice

tests/pos/i8842a.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
inline def f(inline x: Int): Unit = {
2+
inline val twice = x + x
3+
}
4+
5+
def test: Unit = f(3)

tests/pos/i8842b.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
inline def f(inline x: Int): Unit = {
2+
inline val twice = x + x
3+
inline val thrice = twice + x
4+
val res = thrice
5+
res
6+
}
7+
8+
def test: Unit = f(3)

0 commit comments

Comments
 (0)