You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does this mean? In particular, what type argument do we infer for Inv in the object pattern? Do we infer a type? Or does that pattern just mean "check that the value has the classInv but then doesn't actually do a full type test?
If we think of it as a class test, it's almost like we treat it as:
@leafpetersen and I talked about this some and we're currently leaning towards making this an error: If a type in an object pattern has an invariant type parameter and the matched value type doesn't give us enough context to infer a type, then it's simply an error. You either need to use a more specific matched value type (i.e. not Object in the example here), or you need to write the type argument on the pattern (i.e. case Inv<String>() or whatever). There's no way to to write a pattern that means "match Inv for any T".
The text was updated successfully, but these errors were encountered:
munificent
added
request
Requests to resolve a particular developer problem
patterns
Issues related to pattern matching.
and removed
request
Requests to resolve a particular developer problem
labels
Jan 19, 2023
Given:
Consider:
What does this mean? In particular, what type argument do we infer for
Inv
in the object pattern? Do we infer a type? Or does that pattern just mean "check that the value has the classInv
but then doesn't actually do a full type test?If we think of it as a class test, it's almost like we treat it as:
Almost as if the case itself is generic. But we don't actually have type patterns.
If we allow this, then what happens if there is further code that expects us to now know a type, like:
Is there a type we can promote
x
to?Or:
What is the type of
y
?@leafpetersen and I talked about this some and we're currently leaning towards making this an error: If a type in an object pattern has an invariant type parameter and the matched value type doesn't give us enough context to infer a type, then it's simply an error. You either need to use a more specific matched value type (i.e. not
Object
in the example here), or you need to write the type argument on the pattern (i.e.case Inv<String>()
or whatever). There's no way to to write a pattern that means "match Inv for any T".The text was updated successfully, but these errors were encountered: