How to disable "unset private variable" warning

After switching compiler from 3.3.0 to 3.3.1 I started getting a lot of “unset private variable” warnings (hundreds in a single project). This is typically related to code that is using JavaFX and @FXML annotations, like here:

  private var button : javafx.scene.control.Button = _

I short, @FXML will cause assignment of proper value to button based on declaration in related .fxml file, but Scala compiler is not aware of that and is issuing a warning.

Is there a proper way to disable those new warnings?

1 Like

scalac -W says scalac -Wunused:privates, so -Wunused:-privates to disable.

Alternatively, -Wconf:msg=unset private var:s to silence the warning.

Scala 3 doesn’t have the fine-grained category support for messages in Scala 2.


This problem also arises when you do give the variable a value:

class Test(x: Int) : 
  private var y = x
  def show(): Unit = println(y)

(new Test(42)).show()

gives unset private variable on the second line.

Isn’t that a bug, as in false positive warning (“here comes the wolf”) that should be reported?
It is after all not unset…

1 Like

Yes, i think so, have made a report.

Btw, it does not always produce such a warning, I have other private variables where this does not happen. I was not able to find a pattern yet.


I commented on the ticket that Scala 2 says to make it a val.

At issue is not whether the var is initialized with underscore or an explicit value; underscore just means the default value.

It’s warning that button_= is never called.

If the field is set only reflectively, then warnings are – what’s the word for when you subvert the type system and everything the language puts in place to help you write sound code?

It feels natural for a UI framework to be unsafe and written in javascript, such that one is destined for the eternal flames of the underworld.

The word “subvert” is too tame.


Thank you for pointing this out. I should have waited for more opinions before submitting the issue. My apologies.