You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inlinevalmsg="cba".reverse
traitE[T]
deff(using@annotation.implicitNotFound(msg) e: E[Int]):Unit= ()
@main defhello():Unit= f
Output
[error] -- [E172] TypeError:Main.scala:5:27
[error] 5|@main defhello():Unit= f
[error] |^
[error] |Nogiveninstance of typeE[Int] was found for parameter e of method f
Expectation
What happened here is that the complex expression "cba".reverse was assigned to an inline constant which was then used inside an annotation, disabling it. What should happens is one of two things. Either print an error that Scala does not support non-trivial inline expressions used inside annotations, or, it should work:
|Invalid reference to a type variable `Length[A]` found in the annotation argument.
|The variable does not occur as a parameter in the scope of method `f`.
To answer the question in the title of the issue, this should error. There is actually two issues in this issue. The first one (that is related to #22346) is that the inline val should emit an error. In this snippet, it doesn't because an error in Typer is emitted while that check only happens later in InlineVals:
Explanation: The code above should error because the parameter of implicitNotFound should be a constant expression. As of today, "cba".reverse is not a constant expression.
Gedochao
changed the title
Inilne expressions with non-trivial computations inside annotations should work or error
Inline expressions with non-trivial computations inside annotations should work or error
Jan 15, 2025
Compiler version
3.6.2
Minimized code
Output
Expectation
What happened here is that the complex expression
"cba".reverse
was assigned to an inline constant which was then used inside an annotation, disabling it. What should happens is one of two things. Either print an error that Scala does not support non-trivialinline
expressions used inside annotations, or, it should work:Please note that expressions like
"ab" + "c"
already work, even when the concatenation is split into multiple inline constants.The text was updated successfully, but these errors were encountered: