-
Notifications
You must be signed in to change notification settings - Fork 21
Incorrect exhaustiveness warning when pattern matching on Nil.type #12186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That sucks, and 100% going to be due to scala/scala#9208. |
I checked the Jenkins output, and you are correct. the bootstrap introduced an exhaustiveness warning (which we never saw, because we don't have fatal warnings yet). technically, that PR didn't break it so much as expose it, as in principle this can happen for any sealed sum type for which you create a value alias |
Some notes: Compare with the REPL: scala> typeOf[Nil.type] =:= typeOf[scala.collection.immutable.Nil.type]
val res1: Boolean = true One difference is |
Ah, this rings a bell... Unfortunately, phase travel doesn't revert that flag...
|
Though the symbol doesn't change here, and you're saying you see a
|
Yeah, because my reference is the "val alias" scala> object Scala { val Nil: scala.collection.immutable.Nil.type = scala.collection.immutable.Nil }
object Scala
scala> val t = typeOf[Scala.type].member(TermName("Nil"))
val t: $r.intp.global.Symbol = value Nil
scala> t.getClass
val res0: Class[_ <: $r.intp.global.Symbol] = class scala.reflect.internal.Symbols$MethodSymbol
scala> t.isMethod
val res1: Boolean = true |
Ah of course, sorry for the confusion |
I turned on nonexhaustive errors using
causes:
is this the same bug? I can create another one, but if that's already covered, there's no point. Using 2.13.3 causes the code above to compile w/o error or warning. |
@adamw The issue you describe is that multiple extractors can't be shown to be exhaustive together. At the risk of stating the obvious, you can workaround by matching the extractor that extracts a value first, and use a fallback for the other:
|
@NthPortal thanks, though I suppose @martijnhoekstra says it's a feature, not a bug? :) I'd prefer to avoid matching on |
I wouldn't want to call it a feature, just that scala doesn't have a feature to declare extractors that are exhaustive together. Without matching on |
@martijnhoekstra This makes perfect sense, thank you for the explanation! |
@martijnhoekstra In fact, isn't checking head & tail such a common operation on sequences, that it might be justified to add sth like a |
Yes, potentially. They exist in |
|
Here you were only using the last element if available, so matching |
@dwijnand yes true, there was a number of errors I started getting with 2.13.4, and I copied the least representative one of course ;) |
reproduction steps
using Scala 2.13.4-20201011-114304-1c1fa0c (equivalent roughly to HEAD a few days ago)
problem
Nil.type
is the type ofNil
, so the match is exhaustive.In 2.13.3, the same code does not raise an exhaustiveness warning.
Note: it only warns if you use the value alias of
Nil
(from thescala
package, but presumably any value alias as well), and does not warn if you use the fully qualified type.The text was updated successfully, but these errors were encountered: