Closed
Description
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