Skip to content

Quoted pattern should devirtualize member selections #10573

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 Dec 1, 2020 · 1 comment
Closed

Quoted pattern should devirtualize member selections #10573

nicolasstucki opened this issue Dec 1, 2020 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

The semantics still seem incomplete in this implementation.

Consider:

trait A { def foo: Int }
trait B extends A { def foo: Int = 1 }

val e0: Expr[A] = '{ new B }
val e1: Expr[Int] = '{ $e0.foo }

The quoted expression e1 will not match a pattern like '{ ($x: B).foo }, but it should.

Originally posted by @LPTK in #10531 (comment)

@nicolasstucki
Copy link
Contributor Author

Test for this issue

import scala.quoted._

trait A { def foo: Int }
class B extends A { def foo: Int = 1 }

inline def test(): Unit = ${ testExpr() }

def testExpr()(using Quotes): Expr[Unit] = {
  val e0: Expr[A] = '{ new B }
  val e1: Expr[Int] = '{ $e0.foo }
  e1 match
    case '{ ($x: B).foo } => '{}
    case _ => quotes.reflect.report.throwError("did not match")
}
def Test = test()

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 1, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 1, 2020
nicolasstucki added a commit that referenced this issue Dec 7, 2020
Fix #10573: Devirtualize member selection when matching
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

No branches or pull requests

1 participant