使用XScalaWT,這斯卡拉2.7下編譯:斯卡拉2.8:行爲改變了嗎?
class NodeView(parent: Composite) extends Composite(parent) {
var nodeName: Label = null
this.contains(
label(
nodeName = _
)
)
}
隨着2.8.0 RC1,我得到這個錯誤:
type mismatch; found : main.scala.NodeView required: org.eclipse.swt.widgets.Label
的類型是:
label(setups: (Label => Unit)*)(parent: Composite) : Label
contains(setups: (W => Unit)*) : W
所以看起來像_現在綁定到外部函數而不是內部。
這種改變是故意的嗎?
UPDATE:這是一個最小化的例子:
的Scala 2.7.7:
scala> var i = 0
i: Int = 0
scala> def conv(f: Int => Unit) = if (_:Boolean) f(1) else f(0)
conv: ((Int) => Unit)(Boolean) => Unit
scala> def foo(g: Boolean => Unit) { g(true) }
foo: ((Boolean) => Unit)Unit
scala> foo(conv(i = _))
scala> i
res4: Int = 1
的Scala 2.8.0RC3:
scala> var i = 0
i: Int = 0
scala> def conv(f: Int => Unit) = if (_:Boolean) f(1) else f(0)
conv: (f: (Int) => Unit)(Boolean) => Unit
scala> def foo(g: Boolean => Unit) { g(true) }
foo: (g: (Boolean) => Unit)Unit
scala> foo(conv(i = _))
<console>:9: error: type mismatch;
found : Boolean
required: Int
foo(conv(i = _))
^
scala> foo(conv(j => i = j))
scala> i
res3: Int = 1
有趣的是,這個作品:
scala> foo(conv(println _))
1
你能發佈更多或錯誤信息? – 2010-04-29 07:54:21
我沒有發佈錯誤消息:「type mismatch; found:main.scala.NodeView required:org.eclipse.swt.widgets.Label」 – 2010-04-29 08:06:53
編譯器引用哪一行? – 2010-04-29 09:25:38