开发者

Difference in Scala type inference, Eclipse vs. Maven

I'm getting a compilation failure using the Maven Scala plugin that I'm n开发者_C百科ot getting using The Eclipse Scala IDE. First the code:

package com.example

trait SomeTrait[OUTPUT, INPUT] {
    def apply(request: INPUT, f: OUTPUT => Unit);
}

class  SomeClass extends SomeTrait[String,String] {
    def apply(request, f) {
        f.apply(request.toUpperCase())
    }
}

object App extends Application {
  override def main(args: Array[String]) {
      new SomeClass()("test", (value) => { println(value)})
  }
}

Eclipse Scala IDE is fine but Maven gives me this error:

[ERROR] .../src/main/scala/com/example/App.scala:8: 
    error: ':' expected but ',' found.
[INFO]     def apply(request, f) {
[INFO]                      ^
[ERROR] .../src/main/scala/com/example/App.scala:11: 
    error: identifier expected but '}' found.
[INFO] }

If I specify the types, as in:

class  SomeClass extends SomeTrait[String,String] {
    def apply(request: String, f: String => Unit) {
        f.apply(request.toUpperCase())
    }
}

It compiles in both.

Versions etc.:

Scala version: 2.8.1
Scala IDE for Eclipse: 1.0.0.201011130651
Maven: 3.0
Maven Scala Plugin: 2.15.0
Java: 1.6.0_17


Eclipse is wrong here ... you should be seeing the same compile time error there as you do in the command-line case.

What's baffling is that the Scala compiler embedded in Eclipse (which is just scalac 2.8.1.final running in an incremental compilation mode) is managing to successfully compile the source you originally provided and is inferring the argument types that you want ... classfiles are generated, and in the binary output SomeClass.apply has the signature you would expect.

This just shouldn't be happening.

UPDATE:

As Paul noted the IDE is behaving as if -Yinfer-argument-types were enabled. It's also behaving as if -Ydependent-method-types were enabled. Which suggests that there's something awry with the new logic behind the -Xexperimental option which manifests itself when compiler Settings instances are created in the way that the IDE does it.


You're using -Yinfer-argument-types wherever it's working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜