Skip to content
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

Type the quoted patterns as precisely as possible #6742

Merged
merged 2 commits into from
Jul 8, 2019

Conversation

nicolasstucki
Copy link
Contributor

In a pattern match where the contents of the quote are statically known we want to propagate the
type inside the pattern the the binding. For example e will not only be an Expr[T] but also
an Expr[Some[Int]].

(s: Expr[T]) match {
  case e @ '{ Some($x: Int) } =>
    // e: Expr[T & Some[Int]]
    // x: Expr[Int]
}

If the expression in the pattern contains a spliced expression, possibly typed, we also need to propagate the
type of the scrutinee down into the pattern. For example x will not only be an Expr[Boolean] but also
an Expr[T].

(s: Expr[T]) match {
    case e @ '{ $x: Boolean } =>
      // e: Expr[T & Boolean]
      // x: Expr[T & Boolean]
}

@nicolasstucki nicolasstucki force-pushed the fix-type-of-quoted-pattern branch 5 times, most recently from 546cea3 to ecee17d Compare June 28, 2019 11:44
@nicolasstucki nicolasstucki added this to the 0.17 Tech Preview milestone Jun 30, 2019
@nicolasstucki nicolasstucki force-pushed the fix-type-of-quoted-pattern branch 13 times, most recently from 325a113 to 9875979 Compare July 2, 2019 12:12
In a pattern match where the contents of the quote are statically known we want to propagate the
type inside the pattern the the binding. For example `e` will not only be an `Expr[T]` but also
an `Expr[Some[Int]]`.

```scala
(s: Expr[T]) match {
  case e @ '{ Some($x: Int) } =>
    // e: Expr[T & Some[Int]]
    // x: Expr[Int]
}
```

If the expression in the pattern contains a spliced expression, possibly typed, we also need to propagate the
type of the scrutinee down into the pattern. For example `x` will not only be an `Expr[Boolean]` but also
an `Expr[T]`.

```scala
(s: Expr[T]) match {
    case e @ '{ $x: Boolean } =>
      // e: Expr[T & Boolean]
      // x: Expr[T & Boolean]
}
```
@nicolasstucki nicolasstucki force-pushed the fix-type-of-quoted-pattern branch from 9875979 to 1a1e8f6 Compare July 2, 2019 14:15
@nicolasstucki nicolasstucki requested a review from odersky July 2, 2019 15:36
@nicolasstucki nicolasstucki marked this pull request as ready for review July 2, 2019 15:36
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

compiler/src/dotty/tools/dotc/typer/Typer.scala Outdated Show resolved Hide resolved
@odersky odersky assigned nicolasstucki and unassigned odersky Jul 5, 2019
@odersky odersky merged commit 9349faa into scala:master Jul 8, 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