scala / bug

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

quickfixes don't include escapes when needed #12942

Open coreywoodfield opened 4 months ago

coreywoodfield commented 4 months ago

Reproduction steps

Scala version: 2.13.12

In Test.scala:

trait Trait {
  def foo: Any
}
class Test extends Trait{
  case object `val`

  override def foo = `val`
}

When you run scalac -quickfix:any -Xsource:3 Test.scala, the file gets updated to

trait Trait {
  def foo: Any
}
class Test extends Trait{
  case object `val`

  override def foo: Test.this.val.type = `val`
}

which does not compile (the val in the type should be surrounded with backticks)

Problem

Quickfixes should escape keywords as needed

som-snytt commented 4 months ago

Printing with backticks would solve related tickets in REPL and autocomplete.

SethTisue commented 4 months ago

attn @lrytz

lrytz commented 4 months ago

We could special case keywords (80 / 20), that idea is in tree printers https://github.com/scala/scala/blob/v2.13.12/src/reflect/scala/reflect/internal/Printers.scala#L34.

Alternatively sprinkle the BackquotedIdentifierAttachment attachement more widely. @som-snytt wdyt?

Either way, I don't see this as a blocker for 2.13.13.

lrytz commented 4 months ago

WIP: https://github.com/scala/scala/compare/2.13.x...lrytz:scala:t12942?expand=1