-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
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
Exception during macro expansion: java.lang.ClassCastException: class scala.quoted.runtime.impl.ExprImpl cannot be cast to class scala.Product #19941
Comments
Minimizationimport scala.quoted.*
inline def expandMacro(inline from: Tuple): Any =
${ expandMacroImpl }
def expandMacroImpl(using Quotes): Expr[?] =
'{ 1 *: EmptyTuple } match
case '{ ${hd *: tl} : *:[h,t] } => '{ ??? } def test: Any = expandMacro
|
The code has something wrong in The code should not crash, it should fail to match. |
We compute the pattern using `Expr[pt]` of the prototype `pt` of the splice, but this is not enough to reject non-matching patterns. The quoted splices are encoded away before we get to the pattern matching phase where we could potentially detect that they will not match. Instead we check that all quote patterns are `Expr[..]` when typing the pattern. Fixes scala#19941
@nicolasstucki Does this mean the code is invalid or useless for the last member of a non empty tuple? (I assumed the tail case '{scala.Tuple$package.EmptyTuple.*:[t, EmptyTuple.type]($hd)} => For the other cases can I assume this should/will work? TIA |
You probably need something like this case '{ ($hd: h) *: ($tl: t) } => |
@nicolasstucki I had already tried that but compilation failed. Here is what I get: [error] 96 | case '{ ($hd: h) *: ($tl: t) } =>
[error] | ^^^^^^^^^^^
[error] | value *: is not a member of t |
Oh right, you must tell the pattern that case '{ type t <: Tuple; ($hd: h) *: ($tl: t) } => |
Thank you. Compiles. It seems obvious, but only after you have explained 8-) One more question: Above we state |
@nicolasstucki tried the |
That is another bug. I opened #19947 to follow that one. |
We compute the pattern using `Expr[pt]` of the prototype `pt` of the splice, but this is not enough to reject non-matching patterns. The quoted splices are encoded away before we get to the pattern matching phase where we could potentially detect that they will not match. Instead we check that all quote patterns are `Expr[..]` when typing the pattern. Fixes #19941
Compiler version
Version 3.4.0
Minimized code
Output
Expectation
I was expecting to be able to match against any tuple. Note that the
case '{$v : *:[h,t]}
match works fine.The text was updated successfully, but these errors were encountered: