Skip to content

Rewrite with of "onAction = _ => println("x")" with "-source:3.7-migration" leads to invalid code #23023

Closed as duplicate of#22731
@jpsacha

Description

@jpsacha

Compiler version

"3.7.0-RC3"

Minimized code

This is the working code that I can minimize to. The code compiles file, but scalac option -source:3.7-migration generates invalid code

Original file file: ScalaFXHelloWorld.scala:

import scalafx.application.JFXApp3
import scalafx.geometry.Insets
import scalafx.scene.Scene
import scalafx.scene.control.Button
import scalafx.scene.layout.HBox

object ScalaFXHelloWorld extends JFXApp3:

  override def start(): Unit =
    stage = new JFXApp3.PrimaryStage:
      title = "ScalaFX Hello World"
      scene = new Scene:
        content = new HBox:
          padding = Insets(21)
          children +=
            new Button:
              text = "Print Hello World!"
              onAction = _ => println("Hello World!")

File build.sbt

scalaVersion := "3.7.0-RC3"

libraryDependencies +=   "org.scalafx"   %% "scalafx"   % "23.0.1-R34"

scalacOptions ++= Seq(
  "-rewrite",
  "-source:3.7-migration",
)

// Fork a new JVM for 'run' and 'test:run' to avoid JavaFX double initialization problems
fork := true

Output

When the code is build a warning is issued, but code copiles:

[warn] -- Warning: C:\tmp\myscalafxproj\src\main\scala\my\scalafx\ScalaFXHelloWorld.scala:20:27
[warn] 20 |              onAction = _ => println("Hello World!")                                                                                                                                                           
[warn]    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                           
[warn]    |Implicit parameters should be provided with a `using` clause.                                                                                                                                                   
[warn]    |This code can be rewritten automatically under -rewrite -source 3.7-migration.                                                                                                                                  
[warn]    |To disable the warning, please use the following option:                                                                                                                                                        
[warn]    |  "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"                                                                                                                                   
[info] [patched file C:\tmp\myscalafxproj\src\main\scala\my\scalafx\ScalaFXHelloWorld.scala]
[warn] one warning found                                                                                                

The rewritten code, the last line changed, using was added:

package my.scalafx

import scalafx.application.JFXApp3
import scalafx.geometry.Insets
import scalafx.scene.Scene
import scalafx.scene.control.Button
import scalafx.scene.layout.HBox

object ScalaFXHelloWorld extends JFXApp3:

  override def start(): Unit =
    stage = new JFXApp3.PrimaryStage:
      title = "ScalaFX Hello World"
      scene = new Scene:
        content = new HBox:
          padding = Insets(21)
          children +=
            new Button:
              text = "Print Hello World!"
              onAction = using _ => println("Hello World!")

This code will no longer compile.

Expectation

Re-generated code compiles without errors

See also: scalafx/scalafx#421

A simple SBT project is attaches

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions