Skip to content

Macro-generated match gives an exhaustivity warning, even though it shouldn't #12188

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
adamw opened this issue Apr 22, 2021 · 9 comments · Fixed by #12190
Closed

Macro-generated match gives an exhaustivity warning, even though it shouldn't #12188

adamw opened this issue Apr 22, 2021 · 9 comments · Fixed by #12190

Comments

@adamw
Copy link
Contributor

adamw commented Apr 22, 2021

Compiler version

3.0.0-RC3

Minimized example

In a macro, I want to generate a pattern match for a sealed trait/enum, covering each case and performing some actions. The code I've got is the following:

import scala.quoted.*

object MatchTest {
  inline def test[T](inline obj: T): Unit = ${testImpl('obj)}

  def testImpl[T](objExpr: Expr[T])(using qctx: Quotes, t: Type[T]): Expr[Unit] = {
    import qctx.reflect.*

    val obj = objExpr.asTerm
    val cases = obj.tpe.typeSymbol.children.map { child =>
      val subtype = TypeIdent(child)
      val bind = Symbol.newBind(Symbol.spliceOwner, "c", Flags.EmptyFlags, subtype.tpe)
      CaseDef(Bind(bind, Typed(Ref(bind), subtype)), None, '{()}.asTerm)
    }
    val bind = Symbol.newBind(Symbol.spliceOwner, "o", Flags.EmptyFlags, obj.tpe)
    val result = Match(obj, cases)
    println(result.show(using Printer.TreeAnsiCode))
    result.asExprOf[Unit]
  }
}

Tested using:

sealed trait P
case class PC1(a: String) extends P
case class PC2(b: Int) extends P

MatchTest.test(PC2(10): P)

Output

(PC2.apply(10): P) match {
  case c @ (c: PC1) =>
    ()
  case c @ (`c₂`: PC2) =>
    ()
}
[warn] -- [E029] Pattern Match Exhaustivity Warning: Test.scala:25:17
[warn] 25 |  MatchTest.test(PC2(10): P)
[warn]    |                 ^^^^^^^^^^
[warn]    |       match may not be exhaustive.
[warn]    |
[warn]    |       It would fail on pattern case: PC1(_), PC2(_)
[warn]    | This location contains code that was inlined from Test.scala:25

Expectation

I wouldn't expect an exhaustivity warning, as all cases are covered.

I know that the match isn't perfect, but I don't know how to generate a better one. Specifically, instead of c @ (c: PC1), I'd like to generate c @ (_: PC1), but I can't find a way to create a _ using the current macro API. A candidate would be Ident(TermRef(NoPrefix, "_")), but then I don't know how to get a NoPrefix instance.

I also tried adding a third branch with an : Any case, but this didn't help - got the same exhaustivity warning

@liufengyun
Copy link
Contributor

When I compile the snippets with flags:

scalac -d out -Xprint:inlining -Ycheck:all Macro.scalaTest.scala

It ends up with the following expanded tree:

      (PC2.apply(10):P match
        {
          case c @ c:PC1 => ()
          case c @ c:PC2 => ()
        }
      ):Unit

Note that the tree for pattern c @ c: PC1 is different from the desugaring c @ _: PC1 generated by the compiler. Despite that #12190 proposes a fix, I'm not sure if there are other places where the compiler depends on the invariant.

For such use cases, it's recommended to synthesize the code using if/else + isInstanceOf, which is what the pattern match compiles to.

@adamw
Copy link
Contributor Author

adamw commented Apr 22, 2021

Thanks! Not sure I understand though :) Which invariant you are referring to?

I'd like to generate c @ _: PC1 (or even simply c: PC1), but I don't know how to express it with code in a macro. Or are you saying, that in these cases the macro should if+instanceofs?

@liufengyun
Copy link
Contributor

Which invariant you are referring to? I'd like to generate c @ _: PC1 (or even simply c: PC1), but I don't know how to express it with code in a macro.

Yes, I mean c @ _: PC1 where _ has the type PC1. Yes, the current reflect API does not support creating an Ident like that. I am not sure if it's worth supporting it.

are you saying, that in these cases the macro should if+instanceofs?

Yes, generally it's recommended to avoid generating pattern match code in macros. Macros can use if/else + isInstanceOf to implement the same logic, which works better with the compiler (no complex compiler invariants).

@adamw
Copy link
Contributor Author

adamw commented Apr 22, 2021

Ah, I see, thanks :) I'll try rewriting that to if-else then

@smarter
Copy link
Member

smarter commented Apr 22, 2021

Yes, I mean c @ _: PC1 where _ has the type PC1. Yes, the current reflect API does not support creating an Ident like that. I am not sure if it's worth supporting it.

Given that the reflect API supports creating CaseDef and Bind nodes, I think it makes sense to support wildcards in these nodes too otherwise the API will seem incomplete /cc @nicolasstucki

@nicolasstucki
Copy link
Contributor

Yes, it seems we need to support them in the API. I believed that we could use Idents but it doesn't look like it is possible.

@adamw
Copy link
Contributor Author

adamw commented Apr 23, 2021

FYI, I rewrote the match to if-else, works fine :) softwaremill/quicklens@503f439

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Currently we are missing in the API the Wilcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. Currently this tree can be inconsitently
 matched by `Ident` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.
`TypeIdent` is the only one that works as expected.

Changes
* `Ident` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Currently we are missing in the API the Wilcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. Currently this tree can be inconsitently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Currently we are missing in the API the Wilcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. Currently this tree can be inconsitently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
@nicolasstucki
Copy link
Contributor

BTW, @adamw now we have quotes that allows us to from import Quotes without naming it. This is the recommended style:

-  def testImpl[T](objExpr: Expr[T])(using qctx: Quotes, t: Type[T]): Expr[Unit] = {
-    import qctx.reflect.*
+  def testImpl[T: Type](objExpr: Expr[T])(using Quotes): Expr[Unit] = {
+    import quotes.reflect.*

@adamw
Copy link
Contributor Author

adamw commented Apr 23, 2021

@nicolasstucki Thanks! Changed in quicklens :)

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 27, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit that referenced this issue Apr 27, 2021
Fix #12188: Use ascribed type for bindings
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 27, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 27, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 12, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 12, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 17, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 18, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Parial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 27, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 10, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 17, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 17, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `WildcardPattern` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 17, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `WildcardPattern` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 20, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `WildcardPattern` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 20, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `WildcardPattern` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 20, 2021
Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `Ident` does not match `Ident(_)`
* `TypeIdent` does not match `Ident(_)`
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `WildcardPattern` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Fixes scala#12188
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment