Pattern matching with type annotations allows impossible cases
See original GitHub issueThis should not compile:
sealed trait Foo[T]
case class Bar[T](s: String)
def shouldError[T](foo: Foo[T]): String =
foo match {
case bar: Bar[T] => bar.s
}
Not even a warning is produced, as is.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Haskell: ScopedTypeVariables needed in pattern matching ...
When I read the documentation on ScopedTypeVariables , it seems to mean unifying type variables in the function body with the parent function...
Read more >What's New In Python 3.10 — Python 3.11.1 documentation
Patterns consist of sequences, mappings, primitive data types as well as class instances. Pattern matching enables programs to extract information from complex ...
Read more >Python 3.10: Cool New Features for You to Try
In this tutorial, you'll learn about: Debugging with more helpful and precise error messages; Using structural pattern matching to work with data structures ......
Read more >Easier destructuring with type annotations on binding patterns
It would allow for type-safe destructuring of values where the type cannot be inferred by the compiler (such as function parameters). Examples.
Read more >Documentation - Everyday Types - TypeScript
TypeScript allows you to specify the types of both the input and output values of functions. Parameter Type Annotations. When you declare a...
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
A compromise would be to disallow
(foo: Foo) match { case bar: Bar => ...
but allow(foo: Foo) match { case bar: Foo & Bar => ...
More complicated example:
The only thing we know for sure is that
Foo
has a single direct child traitChild
, but we know nothing about the children of the child trait.