gpt4 book ai didi

scala - 缺少非详尽匹配的警告

转载 作者:行者123 更新时间:2023-12-04 15:14:51 24 4
gpt4 key购买 nike

为什么以下不产生警告,当 -unchecked已启用:

object Order {
sealed trait EntryOption
case object EmptyEntry extends EntryOption
trait Entry extends EntryOption

def isEmpty(a: EntryOption): Boolean = a match {
case EmptyEntry => true
// case _: Entry => false
}
}

看来我正好有 same problem before在 Scala 2.8.0 的时代,没有足够的答案。

编辑

@Jed 仅对非抽象类发出警告对我来说没有意义 Entry .考虑以下情况:
trait Order {
sealed trait EntryOption
case object EmptyEntry extends EntryOption
abstract sealed class Entry extends EntryOption

def isEmpty(a: EntryOption): Boolean = a match {
case EmptyEntry => true
// case _: Entry => false
}
}

trait OrderImpl extends Order {
final class EntryImpl extends Entry
}

使警告出现的唯一方法是有一个具体的类 EntryOrder !

最佳答案

它确实在主干上提示:

scala> object Order {
| sealed trait EntryOption
| case object EmptyEntry extends EntryOption
| trait Entry extends EntryOption
|
| def isEmpty( a: EntryOption ) : Boolean = a match {
| case EmptyEntry => true
| // case _: Entry => false
| }
| }
<console>:18: warning: match is not exhaustive!
missing combination Entry

def isEmpty( a: EntryOption ) : Boolean = a match {
^
defined module Order

关于scala - 缺少非详尽匹配的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8291170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com