Skip to content

Commit

Permalink
Merge pull request #10647 from som-snytt/followup/12813-pos
Browse files Browse the repository at this point in the history
Correct position of import selector rename [ci: last-only]
  • Loading branch information
lrytz committed Jan 5, 2024
2 parents 98b7789 + a0f1755 commit 13a80bd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Expand Up @@ -2825,9 +2825,11 @@ self =>
if (!h.isMask)
t.find(_.rename == h.rename).foreach { duplicate =>
val msg =
if (h.isRename || duplicate.isRename) s"${h.rename} is an ambiguous name on import"
if (h.isRename || duplicate.isRename)
if (h.name == duplicate.name) s"${h.name} is renamed twice to ${h.rename}"
else s"${h.rename} is an ambiguous name on import"
else s"${h.rename} is imported twice"
syntaxError(h.namePos, msg)
syntaxError(duplicate.renamePos, msg)
}
h :: checkSelectors(t)
}
Expand All @@ -2852,7 +2854,8 @@ self =>
if (in.token == ARROW || (currentRun.isScala3 && isRawIdent && in.name == nme.as)) {
in.nextToken()
if (name == nme.WILDCARD && !bbq) syntaxError(in.offset, "Wildcard import cannot be renamed")
(wildcardOrIdent(), in.offset)
val pos = in.offset
(wildcardOrIdent(), pos)
}
else if (name == nme.WILDCARD && !bbq) (null, -1)
else (name, start)
Expand Down
12 changes: 6 additions & 6 deletions test/files/neg/t12813.check
@@ -1,16 +1,16 @@
t12813.scala:5: error: a is imported twice
import O.{a, a} // error
^
t12813.scala:8: error: b is an ambiguous name on import
^
t12813.scala:8: error: a is renamed twice to b
import O.{a => b, a => b} // error
^
^
t12813.scala:10: error: b is an ambiguous name on import
import O.{a => b, toString => b} // error
^
^
t12813.scala:11: error: toString is an ambiguous name on import
import O.{a => toString, toString} // error
^
^
t12813.scala:12: error: toString is an ambiguous name on import
import O.{toString, a => toString} // error
^
^
5 errors
12 changes: 6 additions & 6 deletions test/files/neg/t12813b.check
@@ -1,18 +1,18 @@
t12813b.scala:5: error: a is imported twice
import O.{a, a} // error
^
t12813b.scala:8: error: b is an ambiguous name on import
^
t12813b.scala:8: error: a is renamed twice to b
import O.{a => b, a => b} // error
^
^
t12813b.scala:10: error: b is an ambiguous name on import
import O.{a => b, toString => b} // error
^
^
t12813b.scala:11: error: toString is an ambiguous name on import
import O.{a => toString, toString} // error
^
^
t12813b.scala:12: error: toString is an ambiguous name on import
import O.{toString, a => toString} // error
^
^
t12813b.scala:14: error: wildcard import must be in last position
import O.{given, a, _} // error 3
^
Expand Down
4 changes: 4 additions & 0 deletions test/files/neg/t12813c.check
@@ -0,0 +1,4 @@
t12813c.scala:6: error: a is renamed twice to abcdefghij
import O.{a => abcdefghij, a => abcdefghij}
^
1 error
6 changes: 6 additions & 0 deletions test/files/neg/t12813c.scala
@@ -0,0 +1,6 @@

//> abusing options -Vprint:parser -Vpos -Yprint-trees:format

object O { val a = 42 }

import O.{a => abcdefghij, a => abcdefghij}

0 comments on commit 13a80bd

Please sign in to comment.