question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pattern-bound types with bad bounds lead to unsoundness

See original GitHub issue
trait 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:

  1. Disallowing classes with bad bounds on type parameters
  2. Disallowing pat-mat from naming types with bad bounds / only letting pat-mat name types with bounds that are known to be good
  3. 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
smartercommented, Jul 5, 2022

In fact, I think ideally the compiler should define the pattern-bound symbol t to be an alias of x.A instead of an abstract type with some specific bounds, that way we don’t have to special-case them in the checking logic.

1reaction
oderskycommented, Jul 5, 2022

Note that the problem is more general than pattern bound types. For every pattern bound type t with bad bounds L, R, I can also simply write a local type definition

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 p.t instead of t. But the definition of p would be rejected since t has bad bounds. It seems most in the spirit of DOT then to also reject the definition of t with bad bounds at the top-level. And likewise for pattern-bound types.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found