-
Couldn't load subscription status.
- Fork 1.1k
Are warnings ok when matching on generic types? #21995
Unanswered
goshacodes
asked this question in
General Question
-
Compiler version
3.3.4
"-source:future-migration"
Hi. Compiler generates a warning on this code and I know why, but I'm not sure this is ok.
When you match on any - just cast to Matchable, but in this case it creates a mess with nested matches
Minimized code
sealed trait DiffResult extends Product with Serializable case class DiffResultAdditional[T](value: T) extends DiffResult case class Foo() val diffResult: DiffResult = DiffResultAdditional(1) diffResult match { case DiffResultAdditional(foo: Foo) => println("hello") case _ => println("boo") }
Output
Compiles with warning:
pattern selector should be an instance of Matchable, but it has unmatchable type T1ドル instead
This works, but it makes your code a mess
diffResult match {
case DiffResultAdditional(value) =>
value.asInstanceOf[Matchable] match {
case foo: Foo => println("hello")
}
case _ => println("boo")
}
Expectation
compiles without warning
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment