Skip to content

Comparison can't be inlined when using inline values but can with litteral #12794

Description

@Iltotore

Compiler version

3.0.0

Minimized code

First sample:

@main def test = {
  compiletime.preAssert(2 > 1)
}

Second sample:

inline def foo: Int = 2

@main def test = {
  compiletime.preAssert(foo > 1)
}

compiletime.scala

import scala.quoted._

object compileTime {

  inline def preAssert(inline value: Boolean): Boolean = ${preAssertImpl('value)}

  private def preAssertImpl(expr: Expr[Boolean])(using quotes: Quotes): Expr[Boolean] = {

    expr.value match {

      case Some(false) => quotes.reflect.report.error(s"Compile-time assertion failed", expr)

      case None => quotes.reflect.report.warning(s"Unable to evaluate assertion at compile time", expr)

      case _ =>
    }

    expr
  }
}

Output

First sample: The code compiles and is inlined to true

Second sample: The code is _partially inlined (2 > 1 in the bytecode) and the macro can't retrieve the value at compiletime

Unable to evaluate assertion at compile time

Expectation

I expect the compiler to fully inline the second example in order to get the same result as the first one:

foo > 1
//to
2 > 1
//to
true

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions