Skip to content

inline val not inlined #24420

@mbovel

Description

@mbovel

Bug found by @asunluer.

Compiler version

3.0
3.7.4
3.8.0-RC1-bin-20250822-658c8bd-NIGHTLY

Minimized code

inline def f(): Long =
  1L

inline def g(): Long =
  inline val x = f()
  x

inline def h(): Long = 
  inline if g() > 0L then 1L else 0L

@main def main(): Unit =
  println(h())

Output

$ scala -S 3.7.4 inline_val_bug.scala
Compiling project (Scala 3.7.4, JVM (23))
[error] ./inline_val_bug.scala:12:11
[error] Cannot reduce `inline if` because its condition is not a constant value: {
[error]   inline val x: Long = 1L:Long
[error]   x:Long
[error] }:Long > 0L
[error]   println(h())
[error]           ^^^
Error compiling project (Scala 3.7.4, JVM (23))
Compilation failed

Expectation

Compiles, and constant-fold h() to 1L.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions