在使用 scala 的依赖方法类型时,我遇到了与默认方法参数的冲突:
abstract class X {
type Y
case class YY(y: Y)
}
object XX extends X {
type Y = String
}
trait SomeTrait {
def method(x: X)(y: x.YY, default: Int = 3): Unit
}
object SomeObject extends SomeTrait {
def method(x: X)(y: x.YY, default: Int): Unit = {}
method(XX)(XX.YY("abc")) // fails to compile
}
消息是:
[error] found : me.alexbool.XX.YY
[error] required: x$1.YY
[error] Error occurred in an application involving default arguments.
[error] method(XX)(XX.YY("abc")) // fails to compile
如果我从方法定义和实现中删除具有默认值的参数,则该示例将成功编译。我究竟做错了什么?这是一个错误吗?
附注我使用的是 Scala 2.11.4
最佳答案
谷歌搜索了半个小时,我有了答案。 是的,这是一个错误。 https://issues.scala-lang.org/browse/SI-7371
关于scala - 依赖方法类型与默认参数冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27757746/