From 666bbe730aa647a8476a33ca79beba671b80b3d2 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 9 Jun 2012 13:27:31 +0200 Subject: SI-4831 Fix ambiguous import detection for renamed imports. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 6 +++--- test/files/neg/t4831.check | 7 +++++++ test/files/neg/t4831.scala | 11 +++++++++++ test/files/pos/t4831.scala | 11 +++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 test/files/neg/t4831.check create mode 100644 test/files/neg/t4831.scala create mode 100644 test/files/pos/t4831.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2a1af2755f..fec5063bd0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4575,17 +4575,17 @@ trait Typers extends Modes with Adaptations with Tags { qual = atPos(tree.pos.focusStart)(gen.mkAttributedQualifier(pre)) } else { if (impSym.exists) { - var impSym1 = NoSymbol + var impSym1: Symbol = NoSymbol var imports1 = imports.tail def ambiguousImport() = { - if (!(imports.head.qual.tpe =:= imports1.head.qual.tpe)) + if (!(imports.head.qual.tpe =:= imports1.head.qual.tpe && impSym == impSym1)) ambiguousError( "it is imported twice in the same scope by\n"+imports.head + "\nand "+imports1.head) } while (errorContainer == null && !imports1.isEmpty && (!imports.head.isExplicitImport(name) || imports1.head.depth == imports.head.depth)) { - var impSym1 = imports1.head.importedSymbol(name) + impSym1 = imports1.head.importedSymbol(name) if (reallyExists(impSym1)) { if (imports1.head.isExplicitImport(name)) { if (imports.head.isExplicitImport(name) || diff --git a/test/files/neg/t4831.check b/test/files/neg/t4831.check new file mode 100644 index 0000000000..3b8b836f05 --- /dev/null +++ b/test/files/neg/t4831.check @@ -0,0 +1,7 @@ +t4831.scala:10: error: reference to b is ambiguous; +it is imported twice in the same scope by +import O.b +and import O.{a=>b} + println(b) + ^ +one error found diff --git a/test/files/neg/t4831.scala b/test/files/neg/t4831.scala new file mode 100644 index 0000000000..82346ec57d --- /dev/null +++ b/test/files/neg/t4831.scala @@ -0,0 +1,11 @@ +object O { + val a = 0 + val b = 1 +} + +import O.{a => b} +import O.b + +object test { + println(b) +} diff --git a/test/files/pos/t4831.scala b/test/files/pos/t4831.scala new file mode 100644 index 0000000000..48002106e6 --- /dev/null +++ b/test/files/pos/t4831.scala @@ -0,0 +1,11 @@ +object O { + val a = 0 +} + + +object test { + val O1: O.type = O + val O2: O.type = O + import O1.a, O2.a + println(a) +} -- cgit v1.2.3