Skip to content

Fix #6214: Set correct owner for splices in quote patterns #6248

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

Merged
merged 2 commits into from
Apr 6, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 6, 2019

No description provided.

@odersky
Copy link
Contributor Author

odersky commented Apr 6, 2019

@nicolasstucki i6214.scala points out a difference between owners of splices in expressions and patterns:

  def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match {
    case '{ val a: Int = $y; 1} => y                     // owner of `y` is `res`
    case _ => '{ val b: Int = ${val c = 2; c.toExpr}; 1} // owner of `c` is `b`, but that seems to be OK
  }

Just wanted top check with you that that's as intended.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add a test case with nested quoted patterns suc as in

object Test {
  def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match {
    case '{ val a: Int = ${ Foo('{ val b: Int = $y }) }; 1} => y
  }
 object Foo {
   def unapply(x: Expr[Int]): Option[Expr[Int]] = Some(x)
 }
}

object Test {
def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match {
case '{ val a: Int = $y; 1} => y // owner of `y` is `res`
case _ => '{ val b: Int = ${val c = 2; c.toExpr}; 1} // owner of `c` is `b`, but that seems to be OK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is ok. The owner is later changed during the ReifyQuotes.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I also added another test

@odersky odersky merged commit 2cb5dd6 into scala:master Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants