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 matching with type annotations allows impossible cases

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
smartercommented, Jan 11, 2018

A compromise would be to disallow (foo: Foo) match { case bar: Bar => ... but allow (foo: Foo) match { case bar: Foo & Bar => ...

1reaction
smartercommented, Jan 11, 2018

More complicated example:

sealed trait Foo
trait Child extends Foo
case class Bar(s: String)
class Bla extends Bar("") with Child // This could be in a different file

The only thing we know for sure is that Foo has a single direct child trait Child, but we know nothing about the children of the child trait.

Read more comments on GitHub >

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

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