UndoFX icon indicating copy to clipboard operation
UndoFX copied to clipboard

Compile fails in Scala 2.11.7 project

Open benedictleejh opened this issue 8 years ago • 4 comments

I'm using Scala 2.11.7 with UndoFX in my project, and when I try to compile, the compile fails with assertion failed: TVar<?0=null>.

This only happens with UndoFX 1.2, and it was fine before on UndoFX 1.1.1, and the only changes I've made are to comply with 1.2's new interface. I've even changed from using SAM conversion to instantiate the undo manager to anonymous classes, and the failure still takes place. Even a stacktrace simply spits out internal Scala compiler errors, so I can't quite debug what's causing the error.

My build tool is Gradle 2.7, if it means anything.

I've also tried this on a fresh Gradle Scala project, and the same error results.

This is the sample code for the fresh project that fails to compile:

import java.util.function.{Consumer, Function}

import org.fxmisc.undo.UndoManagerFactory
import org.reactfx.EventSource

object Main {
  val changes = new EventSource[Change]

  val undoManager = UndoManagerFactory.unlimitedHistoryUndoManager(
  changes,
  new Function[Change, Change] {
    override def apply(t: Change): Change = t.invert
  },
  new Consumer[Change] {
    override def accept(t: Change): Unit = t.apply()
  }
  )

}

case class Change(oldVal: Boolean, newVal: Boolean) {
  def invert: Change = Change(newVal, oldVal)

  def apply(): Unit = println(newVal)
}

benedictleejh avatar Oct 31 '15 09:10 benedictleejh

Well, if there is an assertion error during compilation, that either means there is a bug in the Scala compiler, or the bytecode of UndoFX is somehow malformed (which is less likely because Java compiler seems to work with it just fine). I would try Scala 2.12.0-M3 and if it still fails, try reporting it to the Scala team.

TomasMikula avatar Oct 31 '15 16:10 TomasMikula

I've tried it on 2.12.0-M3, and the bug still appears. As you've suggested, I've filed an issue to the Scala issue tracker here: https://issues.scala-lang.org/browse/SI-9543

benedictleejh avatar Oct 31 '15 16:10 benedictleejh

:+1:

TomasMikula avatar Oct 31 '15 16:10 TomasMikula

As I've noted in the comment in the Scala language issue, introducing a type parameter to the method call instead of letting Scala infer it allows the code to compile. That is, specifying what T is in UndoManagerFactory.unlimitedHistoryUndoManager[T]() allows working around the type inference failure for the moment.

On a related note, SAM conversion doesn't work for the new method signature in 1.2 as well.

Hopefully, this information is useful to someone working with UndoFX in Scala.

benedictleejh avatar Nov 05 '15 02:11 benedictleejh