scala / bug

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

Double import error message thinks it's a rename import #12813

Closed nafg closed 6 months ago

nafg commented 1 year ago

Reproduction steps

Scala version: 2.13.11

Welcome to Scala 2.13.11 (OpenJDK 64-Bit Server VM, Java 17.0.7).
Type in expressions for evaluation. Or try :help.

scala> object O { val a = 1 }
object O

scala> import O.{a, a}
              ^
       error: a is renamed twice
                 ^

Problem

It's not renamed at all

som-snytt commented 1 year ago

Apparently, it's always been like that...

Welcome to Scala 2.12.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_352).
Type in expressions for evaluation. Or try :help.

scala> object O { val a = 1 }
defined object O

scala> import O.{a, a}
<console>:12: error: a is renamed twice
       import O.{a, a}
              ^

...and always will! [evil cackle]

-- [E122] Syntax Error: ------------------------------------------------------------------------------------------------
1 |import O.{a, a}
  |             ^
  |             a is renamed twice on the same import line.
1 error found
som-snytt commented 1 year ago

The ancient behavior survived refactoring (which is correct for a refactor).

But the useful check is that a name is not introduced twice.

This is perfectly fine:

import x.{toString, toString => show}

except for the subsequent ambiguity for toString.

The spec does not disallow foolish imports.

nafg commented 1 year ago

I suppose one could argue that all imports are just a rename from the fully qualified one to the unprefixed one...

On Tue, Jun 27, 2023, 12:36 PM som-snytt @.***> wrote:

The ancient behavior survived refactoring (which is correct for a refactor).

But the useful check is that a name is not introduced twice.

This is perfectly fine:

import x.{toString, toString => show}

except for the subsequent ambiguity for toString.

The spec does not disallow foolish imports.

— Reply to this email directly, view it on GitHub https://github.com/scala/bug/issues/12813#issuecomment-1609871271, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAYAUAJWXXL6635JUPWNVLXNMDZBANCNFSM6AAAAAAZU6PLD4 . You are receiving this because you authored the thread.Message ID: @.***>

som-snytt commented 1 year ago

Indeed, the spec says import x.a is shorthand for import x.{a => a}, and that's the underlying cause for the odd wording.