-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
When I compile the snippets with flags:
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 For such use cases, it's recommended to synthesize the code using |
Thanks! Not sure I understand though :) Which invariant you are referring to? I'd like to generate |
Yes, I mean
Yes, generally it's recommended to avoid generating pattern match code in macros. Macros can use |
Ah, I see, thanks :) I'll try rewriting that to if-else then |
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 |
Yes, it seems we need to support them in the API. I believed that we could use |
FYI, I rewrote the match to if-else, works fine :) softwaremill/quicklens@503f439 |
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
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
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
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
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
BTW, @adamw now we have - 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.* |
@nicolasstucki Thanks! Changed in quicklens :) |
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
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
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
Fix #12188: Use ascribed type for bindings
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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:
Tested using:
Output
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 generatec @ (_: PC1)
, but I can't find a way to create a_
using the current macro API. A candidate would beIdent(TermRef(NoPrefix, "_"))
, but then I don't know how to get aNoPrefix
instance.I also tried adding a third branch with an
: Any
case, but this didn't help - got the same exhaustivity warningThe text was updated successfully, but these errors were encountered: