-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pattern-bound types with bad bounds lead to unsoundness #15578
Comments
It feels that option 3 is the most logical choice. If we represent type parameters as type members, then binding non-toplevel type arguments would be equivalent to having a type projection. |
Note that the problem is more general than pattern bound types. For every pattern bound type type t >: L <: R with the same effect. In DOT we can't do either since every type has to be a member of an object. So in DOT I'd have to write val p = {
type t >: L <: R
} and then use |
Ah, yes. This solution is indeed more logical and consistent. Thanks for your explanation! :) |
A type bound as a type parameter in a pattern like |
In fact, I think ideally the compiler should define the pattern-bound symbol |
One important thing here is that we will reconstruct subtype relationships / infer GADT constraints from the bounds of top-level type parameters, so ideally we should never reject them (their bounds cannot be bad). |
|
The bound variable, I was referring to the example in my previous message with
If you write trait Box[T]:
val unbox: T
class A:
def foo(box: Box[?]) =
box.unbox Then the inferred result type of |
OK, just wanted to point out that in patterns like |
Yes, to be precise I was talking about patterns of the form |
Ah, can we have patterns like |
No, you can't use the same name twice in a pattern, just like you can't write |
Ah, I just checked, it seems this is easily circumvented with aliases: scala> type Foo[t] = Option[(t,t)]
// defined alias type Foo[t] = Option[(t, t)]
scala> (??? : Option[(Int, String)]) match
| case _ : Foo[t] => 1 We will have to take this into account one way or another. |
Taking a note here: aliases can't actually circumvent the check implemented in #15577, since the type parameter of the alias needs to "aggregate" the bounds from all of its occurences on the RHS of the alias. It seems that with that fix, we're in the clear. |
The problem seems to be that pattern matching lets us name a type argument which does not correspond to a type member with known good bounds. In DOT, we would not be able to refer to
t
, so the issue would not show up.Fixes we have thought of so far:
See also the discussion in #15571 and related PR #15577.
The text was updated successfully, but these errors were encountered: