Skip to content

Commit c30fb9f

Browse files
committed
Fix #3745: check for double imports
1 parent aa6459e commit c30fb9f

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
277277
)
278278
case Import(expr, selectors) =>
279279
val exprTpe = expr.tpe
280+
val seen = mutable.Set.empty[Name]
280281
def checkIdent(ident: untpd.Ident): Unit = {
281282
val name = ident.name.asTermName
282283
if (name != nme.WILDCARD && !exprTpe.member(name).exists && !exprTpe.member(name.toTypeName).exists)
283284
ctx.error(NotAMember(exprTpe, name, "value"), ident.pos)
285+
if (seen(ident.name))
286+
ctx.error(s"${ident.show} is renamed twice", ident.pos)
287+
seen += ident.name
284288
}
285289
selectors.foreach {
286290
case ident: untpd.Ident => checkIdent(ident)

tests/neg/i3745a.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import scala.collection.{ Seq, Seq } // error: Seq is renamed twice

tests/neg/i3745b.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import scala.collection.{ Seq, Seq => _ } // error: Seq is renamed twice

tests/neg/i3745c.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import scala.collection.{ Seq => A, Seq => B } // error: Seq is renamed twice

0 commit comments

Comments
 (0)