Incorrect compiler error “Unable to emit reference to method” with 3-RC2
See original GitHub issueCompiler version
3.0.0-RC2
Minimized code
Do not have minimized code. It happens in a larger code base. Not clear how to minimize it on a very concise way. Observed incorrect behavior is described below.
Description
The following line of code does not compile with Scala 3.0.0-RC2 (no errors in Scala 2):
tableView.selectionModel.value.clearSelection()
It produces an error:
Unable to emit reference to method clearSelection in class MultipleSelectionModelBase, class MultipleSelectionModelBase is not accessible in class TableViewSpec
tableView.selectionModel.value.clearSelection()
However, the following code, that adds a helper variable h1
, will compile:
val h1 = tableView.selectionModel.value
h1.clearSelection()
This will compile as well:
tableView.selectionModel.apply().clearSelection()
where
def apply(): T = value
but this will not:
val h2 = tableView.selectionModel
h2.value.clearSelection()
with similar error:
Unable to emit reference to method clearSelection in class MultipleSelectionModelBase, class MultipleSelectionModelBase is not accessible in class TableViewSpec
h2.value.clearSelection()
This error happens in ScalaFX code base. I was looking at reducing code to reproduce the behavior it, but I do not see yet a clear way do that (help appreciated).
Some background on clearSelection()
. It is defined “public” in a package private Java class but inherited in another “public” Java class that is used in Scala code. Here are fragments of the Java code (JavaFX) that shows relationship between types:
public abstract class TableSelectionModel<T> extends MultipleSelectionModelBase<T> {
...
}
abstract class MultipleSelectionModelBase<T> extends MultipleSelectionModel<T> {
...
@Override public void clearSelection() { ... }
}
- property
tableView.selectionModel
is of typeObjectProperty[jfxsc.TableView.TableViewSelectionModel[String]]
that stores a value of typejfxsc.TableView.TableViewSelectionModel[String]
. The prefixjfxsc
indicates that this comes from Java packagejavafx.scene.control
- method
value
returns that value of typejfxsc.TableView.TableViewSelectionModel[String]
- methods
clearSelection()
is inherited byTableViewSelectionModel
fromMultipleSelectionModelBase
that shows up in the error message
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Minimized:
Model.java
i12091.scala
I created a branch that shows the error: https://github.com/scalafx/scalafx/tree/12091_bug_demo Commit: https://github.com/scalafx/scalafx/commit/94c7a755e662cf675b946362fd6348ee9e56d874
Specific line 85 of TableViewSpec code that is causing the issue: https://github.com/scalafx/scalafx/blob/94c7a755e662cf675b946362fd6348ee9e56d874/scalafx/src/test/scala/scalafx/scene/control/TableViewSpec.scala#L85
It is in the test code, just run
test
command on the sbt promptThe commit is not introducing the the error. It just provides an existing code that illustrates the issue.
Line 92 that is effectively equivalent and is not producing the error: https://github.com/scalafx/scalafx/blob/94c7a755e662cf675b946362fd6348ee9e56d874/scalafx/src/test/scala/scalafx/scene/control/TableViewSpec.scala#L92 It is basically:
from the original description above.