Skip to content
Closed
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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,10 @@ class Inliner(val call: tpd.Tree)(using Context):
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =
val vdef1 =
if sym.is(Inline) then
val rhs = typed(vdef.rhs)
val rhs =
typed(vdef.rhs) match
case ConstantValue(v) => Literal(Constant(v))
case rhs => rhs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we directly report an error here?

sym.info = rhs.tpe
untpd.cpy.ValDef(vdef)(vdef.name, untpd.TypeTree(rhs.tpe), untpd.TypedSplice(rhs))
else vdef
Expand Down
9 changes: 9 additions & 0 deletions tests/run/i24420-inline-val-constant.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
inline def f1(): Long =
1L

inline def f3(): Long =
inline val x = f1()
x

@main def Test: Unit =
assert(f3() == 1L)
Loading