Skip to content

Regression for inline if when condition is defined in trait #16641

Closed
@WojciechMazur

Description

@WojciechMazur

Based on Open CB failure for zio/izumi-reflect Open CB #37007

Bisect points to 342ebf3

Compiler version

3.3.0-RC1-bin-20230105-b65b0f2-NIGHTLY

Minimized code

trait Logger {
  inline def debug: debug = valueOf[debug]
  final type debug = false

  // fails
  inline final def log(inline s: String): Unit = {
    inline if (debug) println(" -> " + s)
  }
}

trait BaseLogger extends Logger {
  // fails
  def bar() = log("case1")
}

object Logger {
  // works
  inline def log(inline shift: Int, s: String): Unit = {
    inline if (valueOf[Logger#debug]) println(" " * shift + " -> " + s)
  }
}

@main def Test = {
  val x: BaseLogger = ???
  // fails
  x.log("case2")
  Logger.log(2, "bar")
}

Output

-- Error: /workspace/bisect/test.scala:13:17 -----------------------------------
13 |  def bar() = log("case1")
   |              ^^^^^^^^^^^^
   |Cannot reduce `inline if` because its condition is not a constant value: {
   |  val Logger_this: (Logger_this² : (BaseLogger.this : BaseLogger)) =
   |    Logger_this²
   |  {
   |    given val ev: ValueOf[(false : Boolean)] =
   |      new ValueOf[(false : Boolean)](false)
   |    false
   |  }:Logger_this.debug:Logger_this.debug
   |}
   |
   |where:    Logger_this  is a value in method bar
   |          Logger_this² is a value in method bar
   |----------------------------------------------------------------------------
   |Inline stack trace
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from test.scala:7
 7 |    inline if (debug) println(" -> " + s)
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ----------------------------------------------------------------------------

Expectation

Should compile

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions