Pattern-bound types with bad bounds lead to unsoundness
See original GitHub issuetrait Foo[X >: Any <: Nothing]
@main def Test = (None: Option[Foo[?]]) match {
case _: Option[Foo[t]] =>
val unsound: Nothing = (5 : Any) : t
(unsound : Unit => Unit).apply(())
}
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:
- Disallowing classes with bad bounds on type parameters
- Disallowing pat-mat from naming types with bad bounds / only letting pat-mat name types with bounds that are known to be good
- Disallowing pat-mat from naming type arguments which are not top-level
See also the discussion in https://github.com/lampepfl/dotty/pull/15571 and related PR https://github.com/lampepfl/dotty/pull/15577.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:15 (13 by maintainers)
Top Results From Across the Web
arXiv:2209.07427v1 [cs.PL] 15 Sep 2022
2Interestingly, only reasoning about type equations leads to some paradoxes ... The stratified typing level hierarchy tackles the bad bounds ...
Read more >Theoretical Foundations for Objects with Pattern Matching and ...
2Interestingly, only reasoning about type equations leads to some ... The stratified typing level hierarchy tackles the bad bounds problem [Amin et al....
Read more >[PATCH] Rust cross testing integration with oe-selftest.
Even if the test execution completes early due to failure then we have to wait till this timeout. I tried reducing the timeout...
Read more >(PDF) A case for DOT: Theoretical Foundations for Objects With ...
But combining generic classes with this form of refining type tests leads to ... The stratified typing level hierarchy tackles the bad bounds...
Read more >A practical soft type system for Scheme - Document - Gale
But such a discipline limits the subsets of the data domain (i.e., types) over which ... and assignment leads to an unsound type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In fact, I think ideally the compiler should define the pattern-bound symbol
t
to be an alias ofx.A
instead of an abstract type with some specific bounds, that way we don’t have to special-case them in the checking logic.Note that the problem is more general than pattern bound types. For every pattern bound type
t
with bad boundsL
,R
, I can also simply write a local type definitionwith 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
and then use
p.t
instead oft
. But the definition ofp
would be rejected sincet
has bad bounds. It seems most in the spirit of DOT then to also reject the definition oft
with bad bounds at the top-level. And likewise for pattern-bound types.