From 8c99865cecf41b844e0710620337d26838e647ef Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 9 Mar 2016 18:55:24 +0100 Subject: [PATCH] Fix bug where ambiguous references were not reported There was a mssing condition which meant Tyepr thought it was at the outermost scope where but was mistaken. Fixes #1145 --- src/dotty/tools/dotc/typer/Typer.scala | 3 ++- tests/neg/i1145.scala | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i1145.scala diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 84344dbb1277..fdb92a40b1d1 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -232,7 +232,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } val curImport = ctx.importInfo - if (curImport != null && curImport.isRootImport && previous.exists) return previous + if (ctx.owner.is(Package) && curImport != null && curImport.isRootImport && previous.exists) + return previous // no more conflicts possible in this case // would import of kind `prec` be not shadowed by a nested higher-precedence definition? def isPossibleImport(prec: Int) = prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope) diff --git a/tests/neg/i1145.scala b/tests/neg/i1145.scala new file mode 100644 index 000000000000..b33300b912ae --- /dev/null +++ b/tests/neg/i1145.scala @@ -0,0 +1,11 @@ +object A { + def x = 3 + + def y = { + import B._ + x // error: ambiguous + } +} +object B { + def x = 3 +}