diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index cc8a9097311c..f84263a98760 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -253,14 +253,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit !noImports && (prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope)) - @tailrec def loop(implicit ctx: Context): Type = { + @tailrec def loop(lastCtx: Context)(implicit ctx: Context): Type = { if (ctx.scope == null) previous else { - val outer = ctx.outer var result: Type = NoType // find definition - if ((ctx.scope ne outer.scope) || (ctx.owner ne outer.owner)) { + if ((lastCtx eq ctx) || (ctx.scope ne lastCtx.scope) || (ctx.owner ne lastCtx.owner)) { val defDenot = ctx.denotNamed(name) if (qualifies(defDenot)) { val curOwner = ctx.owner @@ -275,13 +274,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (defDenot.symbol is Package) result = checkNewOrShadowed(previous orElse found, packageClause) else if (prevPrec < packageClause) - result = findRef(found, packageClause, ctx)(outer) + result = findRef(found, packageClause, ctx)(ctx.outer) } } } if (result.exists) result else { // find import + val outer = ctx.outer val curImport = ctx.importInfo def updateUnimported() = if (curImport.unimported.exists) unimported += curImport.unimported @@ -297,20 +297,21 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit findRef(checkNewOrShadowed(wildImp, wildImport), wildImport, ctx)(outer) else { updateUnimported() - loop(outer) + loop(ctx)(outer) } } else { updateUnimported() - loop(outer) + loop(ctx)(outer) } } - else loop(outer) + else loop(ctx)(outer) } } } - loop + // begin findRef + loop(ctx)(ctx) } // begin typedIdent diff --git a/tests/neg/i1641.scala b/tests/neg/i1641.scala index db1daf79166a..659816b3bb5d 100644 --- a/tests/neg/i1641.scala +++ b/tests/neg/i1641.scala @@ -2,7 +2,7 @@ package bar { object bippy extends (Double => String) { def apply(x: Double): St package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" } object Test { def main(args: Array[String]): Unit = { - println(bar.bippy(5.5)) + println(bar.bippy(5.5)) // error println(bar.bippy(1, 2, 3)) // error } } diff --git a/tests/pos/i2324.scala b/tests/pos/i2324.scala new file mode 100644 index 000000000000..b150334e6958 --- /dev/null +++ b/tests/pos/i2324.scala @@ -0,0 +1,16 @@ +object A { + def foo: Int = 1 +} +object B { + def foo: Int = 2 +} +class C { + import A._ + import B._ + + def bar: Int = 4 + + def foo: Int = 3 + + println(foo) +}