【问题标题】:Dependent method types conflict with default arguments依赖方法类型与默认参数冲突
【发布时间】:2015-03-01 16:55:12
【问题描述】:

在玩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

如果我从方法定义和实现中删除具有默认值的参数,则示例编译成功。我究竟做错了什么?是bug吗?

附:我正在使用 Scala 2.11.4

【问题讨论】:

  • 对我来说似乎是个错误。

标签: scala dependent-type default-arguments path-dependent-type dependent-method-type


【解决方案1】:

半小时谷歌搜索,我有一个答案。 是的,这是一个错误。 https://issues.scala-lang.org/browse/SI-7371

【讨论】:

    猜你喜欢
    • 2015-12-04
    • 2018-10-24
    • 2016-11-05
    • 2017-10-15
    • 2019-08-08
    • 2021-11-05
    • 2018-11-20
    • 2019-06-28
    相关资源
    最近更新 更多