Skip to content

Quote pattern spliced expression has wrong type #6999

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

Closed
nicolasstucki opened this issue Aug 6, 2019 · 4 comments
Closed

Quote pattern spliced expression has wrong type #6999

nicolasstucki opened this issue Aug 6, 2019 · 4 comments

Comments

@nicolasstucki
Copy link
Contributor

minimized code

def expr(e: Expr[Any]) = {
  val '{ $x: $t } = e
  '{
    val a: $t = $x
   }
}
30 |        val a: $t = $x
   |                     ^
   |                     Found:    scala.quoted.Expr[Any](x)
   |                     Required: quoted.Expr[t.T]

expectation

x should have type quoted.Expr[t.T]

@anatoliykmetyuk
Copy link
Contributor

Also note the compiler crash described in #6997 when trying to cast, I think these two can be different issues

@nicolasstucki
Copy link
Contributor Author

Actually the issue is type avoidance which seems to do exactly what it should.

val $1$: (scala.quoted.Expr[Any], scala.quoted.Type[_]) = e:quoted.Expr[Any](e) @unchecked match {  ...  }
val x: scala.quoted.Expr[Any] = $1$._1
val t: scala.quoted.Type[_] = $1$._2
'{ ... }

The correct way to express this is to write the complete pattern match

e match {
  case '{ $x: $t } => 
    '{ val a: $t = $x }
}

@nicolasstucki
Copy link
Contributor Author

With new syntax it is possible to unpack on one line

e match case '{ $x: $t } =>
'{ val a: $t = $x }

@nicolasstucki
Copy link
Contributor Author

The best we can do is to emit an error if a val pattern used type splices and guide the user to rewrite it as a match.

nicolasstucki added a commit that referenced this issue Nov 20, 2019
Fix #6999: Emit an error when using type splice in quoted val pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants