We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0.0
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 } }
First sample: The code compiles and is inlined to true
true
Second sample: The code is _partially inlined (2 > 1 in the bytecode) and the macro can't retrieve the value at compiletime
2 > 1
Unable to evaluate assertion at compile time
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
The text was updated successfully, but these errors were encountered:
It would probably have to be
transparent inline def foo: Int = 2
Can you try with that variant?
Sorry, something went wrong.
It works. Thank you.
I don't see any mention of this behaviour in the Transparent Inline method paragraph. If it's not mentionned, maybe this should be added ?
Maybe this comment should be a faq: #12700 (comment)
Kordyjan
No branches or pull requests
Compiler version
3.0.0
Minimized code
First sample:
Second sample:
compiletime.scala
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 compiletimeExpectation
I expect the compiler to fully inline the second example in order to get the same result as the first one:
The text was updated successfully, but these errors were encountered: