Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

"Unreachable case" warning when pattern matching on an option of opaque type #19254

Unanswered
avella2409 asked this question in General Question
Discussion options

Hello, when using an opaque type I've encountered a behavior that I was not expecting.
I would like to understand why in the following example, when using List, I got an Unreachable case warning, but when using Set, everything is fine. I know that List is a class and Set is a trait but have no idea why it says Unreachable case.

object Context {
 opaque type SomeOpaqueType[A] <: A = A
}
import Context.*
def unreachableCaseExample(): Unit = 
 val errorWithList: Option[SomeOpaqueType[List[String]]] = ???
 errorWithList match
 case Some(value) => ??? // 'Unreachable case' error
 case None => ???
 val worksWithSet: Option[SomeOpaqueType[Set[String]]] = ???
 worksWithSet match
 case Some(value) => ??? // Everything is fine
 case None => ???

Do you have any idea? (Scala 3.3.1)

You must be logged in to vote

Replies: 1 comment

Comment options

Looks like a bug to me.

The cause might be related to the fact that List is covariant but Set isn't.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /