【问题标题】:Why does space in backtick constructor params break the compiler?为什么反引号构造函数参数中的空格会破坏编译器?
【发布时间】:2016-02-10 10:16:23
【问题描述】:

在参数名称中,空格和排序以及反引号的某种组合,其中反引号名称与另一个参数具有相同的前导字符,似乎会误导编译器产生编译错误:

声明

case class A(`abc def`: List[Int], abc: String)

导致

[info] Compiling 7 Scala sources to ...
[error] (test:compileIncremental) scala.reflect.internal.Types$TypeError: type mismatch;
[error]  found   : List
[error]  required: String
[error] Total time: 2 s, completed Feb 10, 2016 11:09:51 AM

这个问题似乎取决于参数的顺序和类型以及声明的类型,因为以下所有编译都很好:

case class A(abc: String, `abc def`: List[Int])
case class B(`abc def`: String, abc: String)
case class C(`bbc def`: List[Int], abc: String)
def x(`abc def`: List[Int], abc: String) = 42

这是一个错误还是某种预期?

Scala 2.11.7

【问题讨论】:

    标签: scala scalac


    【解决方案1】:

    【讨论】:

    • 正确。这似乎是这里的情况。感谢您的澄清,本
    猜你喜欢
    • 2015-10-12
    • 1970-01-01
    • 2013-12-19
    • 2012-03-02
    • 2020-02-29
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多