Skip to content

constant Option is not recognised as constant value in inline if #17788

@rssh

Description

@rssh

Compiler version

current (Tue Jan 11 08:53:51 EET 2022) master

Minimized code

object Test {

  inline def get: Option[String] = Some("")

  inline def fun: Unit =
    inline if (get.isDefined) then
      println("value = ${get.get}")
    else
      println("value not set")

  fun

}

Output

[info] welcome to sbt 1.5.5 (Homebrew Java 17)
[info] loading global plugins from /Users/rssh/.sbt/1.0/plugins
[info] loading project definition from /Users/rssh/tests/dotty/compileTimeIfOpt/project
[info] loading settings for project root from build.sbt ...
[info] set current project to test (in build file:/Users/rssh/tests/dotty/compileTimeIfOpt/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source to /Users/rssh/tests/dotty/compileTimeIfOpt/target/scala-3.1.2-RC1-bin-SNAPSHOT/classes ...
[error] -- Error: /Users/rssh/tests/dotty/compileTimeIfOpt/src/main/scala/x/Test.scala:13:2 
[error] 13 |  fun
[error]    |  ^^^
[error]    |Cannot reduce `inline if` because its condition is not a constant value: (Some.apply[String](""):Option[String]).isDefined
[error]    | This location contains code that was inlined from Test.scala:8

Expectation

Should be compiled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions