question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect compiler error “Unable to emit reference to method” with 3-RC2

See original GitHub issue

Compiler 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 type ObjectProperty[jfxsc.TableView.TableViewSelectionModel[String]] that stores a value of type jfxsc.TableView.TableViewSelectionModel[String]. The prefix jfxsc indicates that this comes from Java package javafx.scene.control
  • method value returns that value of type jfxsc.TableView.TableViewSelectionModel[String]
  • methods clearSelection() is inherited by TableViewSelectionModel from MultipleSelectionModelBase that shows up in the error message

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
griggtcommented, Apr 14, 2021

Minimized:

Model.java

package foo;

class ModelBase {  // must not be public
    public void clear() {}
}

public class Model extends ModelBase {}

i12091.scala

import foo.Model

class Property[T] {
  def value: T = ???
  def get(): T = ???
}

class Test {
  def ko(model: Property[Model]):  Unit = model.value.clear()    // error

  def ok(model: Model):            Unit = model.clear()          // ok

  def ok1(model: Property[Model]): Unit = model.get().clear()    // ok

  def ok2(model: Property[Model]): Unit = { val x = model.value; x.clear() }  // ok
}
$ javac -version
javac 1.8.0_282

$ dotc -version
Scala compiler version 3.0.0-RC2 -- Copyright 2002-2021, LAMP/EPFL

$ javac -d . Model.java && dotc i12091.scala 
-- Error: i12091.scala:9:42 ----------------------------------------------------------------
9 |  def ko(model: Property[Model]):  Unit = model.value.clear()    // error
  |                                          ^^^^^^^^^^^
  |Unable to emit reference to method clear in class ModelBase, class ModelBase is not accessible in class Test
2reactions
jpsachacommented, Apr 14, 2021

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

[error] -- Error: ... scalafx\src\test\scala\scalafx\scene\control\TableViewSpec.scala:85:4
[error] 85 |    tableView.selectionModel.value.clearSelection()
[error]    |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |Unable to emit reference to method clearSelection in class MultipleSelectionModelBase, class MultipleSelectionModelBase is not accessible in class TableViewSpec

It is in the test code, just run test command on the sbt prompt

The 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:

tableView.selectionModel.apply().clearSelection()

from the original description above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect compiler error "Unable to emit reference to method ...
Incorrect compiler error "Unable to emit reference to method" with 3-RC2 · property tableView.selectionModel is of type ObjectProperty[jfxsc.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found