scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Quickfix minor formatting issue #12956

Closed vasilmkd closed 4 months ago

vasilmkd commented 4 months ago

Reproduction steps

Scala version: 2.13.12 and 2.13.13

// scalac: -Xsource:3 -Xmigration

trait T { def f: Object }

class K extends T { val f = "" }

Compiler output:

traits.scala:3: warning: under -Xsource:3, inferred Object instead of String [quickfixable]
class K extends T { val f = "" }

Problem

Applying the quickfix produces the following source code:

trait T { def f: Object }

class K extends T { val f : String= "" }

A nicer formatting would be:

trait T { def f: Object }

class K extends T { val f: String = "" }
lrytz commented 4 months ago

When I try this on the command line i get the desired formatting (using 2.13.13). How did you run the compiler?

➜ sandbox cat A.scala
trait T { def f: Object }
class K extends T { val f = "" }
➜ sandbox sc A.scala -Xsource:3 -quickfix:any
A.scala:2: error: [rewritten by -quickfix] under -Xsource:3-cross, the inferred type changes to Object instead of String
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=K.f
class K extends T { val f = "" }
                        ^
1 error
➜ sandbox cat A.scala
trait T { def f: Object }
class K extends T { val f: String = "" }
➜ sandbox
vasilmkd commented 4 months ago

Hmmm, maybe I got confused earlier today. Indeed I only reproduce the problem on Scala 2.13.12 with the same Scala source and the following scalac invocation:

scalac A.scala -Xsource:3 -quickfix:any
som-snytt commented 4 months ago

Yesterday, I nearly commented on a dotty ticket before noticing that I'd make a mistake somewhere in compile/run/version. (scala-cli was also involved as a complication.)

I would like a shell mode where it tracks exactly what I tried and in what order and also captures outputs.

It worked a bit to use -Dscala.repl.info so repl transcript shows the version.