The mysterious default member of type A1 => B1

Here is an odd situation where the method argument name is apparently obscured by another character (which one?) Of type A1 => B1:

object OddBug extends scala.swing.Action(null) {
  def apply() = ()

  def foo(default: String): scala.swing.Component = {
    val res = new scala.swing.TextField(16)
    res.listenTo(res)
    res.reactions += {
      case scala.swing.event.EditDone(_) =>
        if (res.text.isEmpty) res.text = default  // !
    }
    res
  }
}

The compiler says:

[error]  ...: type mismatch;
[error]  found   : A1 => B1
[error]  required: String
[error]         if (res.text.isEmpty) res.text = default
[error]                                          ^

Is this a bug in the compiler (Scala 2.10.3)? Since I can refer to defaultout of reaction, I suspect that this is a problem with PartialFunction.


The workaround is as follows:

  def foo(default: String): scala.swing.Component = {
    val res = new scala.swing.TextField(16)
    res.listenTo(res)
    def fixDefault: String = default
    res.reactions += {
      case scala.swing.event.EditDone(_) =>
        if (res.text.isEmpty) res.text = fixDefault
    }
    res
  }
+4
source share
1 answer

According to @ travis-brown, this is probably a leak from the desorption of the partial function literal. Presented as SI-8329 .

0
source

All Articles