From 184efe19a869fb0e42188ca84d5f5271fc4f2dc8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 28 Apr 2017 16:53:39 +0200 Subject: [PATCH 1/3] Fix #2324: Check contexts in right order when looking for idents The previous logic would look for members of a class in the outermost scope where the class is owner. But it should be the innermost scope. --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 From c18da4dffe4725031ab501f208fe09bac6425998 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 28 Apr 2017 17:02:35 +0200 Subject: [PATCH 2/3] Update neg test --- tests/neg/i1641.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } } From 07f7b1fb238833058b20955dfd6b7ead1ebbeb5d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 28 Apr 2017 17:02:44 +0200 Subject: [PATCH 3/3] Add pos test --- tests/pos/i2324.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/pos/i2324.scala 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) +}