You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
valbuffer:List[String|Int|Long|Char] =List("string", 1, 2l, 'p', 3l, "sss", 2)
buffer.foreach { a =>
a match {
case_: String|Char=> println(s"$a is ")
case _ => println(s"$a is not ")
}
}
the char p is not match String | Char
Output
string is
1 is not
2 is not
p is not
3 is not
sss is
2 is not
But if I put a bracket around the type:
buffer.foreach { a =>
a match {
case_: (String|Char) => println(s"$a is ")
case _ => println(s"$a is not ")
}
}
the output is right
string is
1 is not
2 is not
p is
3 is not
sss is
2 is not
The text was updated successfully, but these errors were encountered:
... on the other hand, we should emit a warning in this case since it's clear that the object Char is not reachable since the scrutinee type is String | Int | Long | Char. I've opened an issue to keep track of that: #8711
Minimized code
when using pattern match in union type like :
the char
p
is not matchString | Char
Output
But if I put a bracket around the type:
the output is right
The text was updated successfully, but these errors were encountered: