From 32f31b8924d16074679bfa0857019d3ba078c4a2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 29 Oct 2015 18:51:33 +0100 Subject: Fix #884 - misdiagnosed ambiguous definition. Universal equality strikes again. Caused a bug in isDefinedInCurrentUnit. --- src/dotty/tools/dotc/typer/Typer.scala | 2 +- test/dotc/tests.scala | 4 ++-- tests/neg/typedIdents.scala | 34 --------------------------------- tests/neg/typedIdents/PQ.scala | 6 ++++++ tests/neg/typedIdents/typedIdents.scala | 28 +++++++++++++++++++++++++++ tests/pos/i884.scala | 4 ++++ tests/pos/overloadedAccess.scala | 1 - tests/pos/typedIdents.scala | 34 --------------------------------- tests/pos/typedIdents/PQ.scala | 6 ++++++ 9 files changed, 47 insertions(+), 72 deletions(-) delete mode 100644 tests/neg/typedIdents.scala create mode 100644 tests/neg/typedIdents/PQ.scala create mode 100644 tests/neg/typedIdents/typedIdents.scala create mode 100644 tests/pos/i884.scala delete mode 100644 tests/pos/typedIdents.scala create mode 100644 tests/pos/typedIdents/PQ.scala diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 52ea32bbc..3ca728895 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -200,7 +200,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit */ def isDefinedInCurrentUnit(denot: Denotation): Boolean = denot match { case MultiDenotation(d1, d2) => isDefinedInCurrentUnit(d1) || isDefinedInCurrentUnit(d2) - case denot: SingleDenotation => denot.symbol.sourceFile == ctx.source + case denot: SingleDenotation => denot.symbol.sourceFile == ctx.source.file } /** Is `denot` the denotation of a self symbol? */ diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 337285c04..68aee49a2 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -77,7 +77,7 @@ class tests extends CompilerTest { @Test def pos_desugar() = compileFile(posDir, "desugar", twice) @Test def pos_sigs() = compileFile(posDir, "sigs", twice) @Test def pos_typers() = compileFile(posDir, "typers", twice) - @Test def pos_typedidents() = compileFile(posDir, "typedIdents", twice) + @Test def pos_typedIdents() = compileDir(posDir, "typedIdents", twice) @Test def pos_assignments() = compileFile(posDir, "assignments", twice) @Test def pos_packageobject() = compileFile(posDir, "packageobject", twice) @Test def pos_overloaded() = compileFile(posDir, "overloaded", twice) @@ -103,7 +103,7 @@ class tests extends CompilerTest { @Test def neg_abstractOverride() = compileFile(negDir, "abstract-override", xerrors = 2) @Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 1) @Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 4) - @Test def neg_typedidents() = compileFile(negDir, "typedIdents", xerrors = 2) + @Test def neg_typedIdents() = compileDir(negDir, "typedIdents", xerrors = 2) @Test def neg_assignments() = compileFile(negDir, "assignments", xerrors = 3) @Test def neg_typers() = compileFile(negDir, "typers", xerrors = 14)(allowDoubleBindings) @Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2) diff --git a/tests/neg/typedIdents.scala b/tests/neg/typedIdents.scala deleted file mode 100644 index cb7cca743..000000000 --- a/tests/neg/typedIdents.scala +++ /dev/null @@ -1,34 +0,0 @@ -package P { - object X { val x = 1; val y = 2 } -} -package Q { - object X { val x = true; val y = "" } -} -package P { // `X' bound by package clause - import Console._ // `println' bound by wildcard import - object A { - println("L4: " + X) // `X' refers to `P.X' here - object B { - import Q._ // `X' bound by wildcard import - println("L7: " + X) // `X' refers to `Q.X' here - import X._ // `x' and `y' bound by wildcard import - println("L8: " + x) // `x' refers to `Q.X.x' here - object C { - val x = 3 // `x' bound by local definition - println("L12: " + x) // `x' refers to constant `3' here - locally { - import Q.X._ // `x' and `y' bound by wildcard import - println("L14: " + x) // reference to `x' is ambiguous here - import X.y // `y' bound by explicit import - println("L16: " + y) // `y' refers to `Q.X.y' here - locally { - import P.X._ // `x' and `y' bound by wildcard import - val x = "abc" // `x' bound by local definition - println("L19: " + y) // reference to `y' is ambiguous here - println("L20: " + x) // `x' refers to string ``abc'' here - } - } - } - } - } -} diff --git a/tests/neg/typedIdents/PQ.scala b/tests/neg/typedIdents/PQ.scala new file mode 100644 index 000000000..8a5afede0 --- /dev/null +++ b/tests/neg/typedIdents/PQ.scala @@ -0,0 +1,6 @@ +package P { + object X { val x = 1; val y = 2 } +} +package Q { + object X { val x = true; val y = "" } +} diff --git a/tests/neg/typedIdents/typedIdents.scala b/tests/neg/typedIdents/typedIdents.scala new file mode 100644 index 000000000..4937edfe3 --- /dev/null +++ b/tests/neg/typedIdents/typedIdents.scala @@ -0,0 +1,28 @@ +package P { // `X' bound by package clause + import Console._ // `println' bound by wildcard import + object A { + println("L4: " + X) // `X' refers to `P.X' here + object B { + import Q._ // `X' bound by wildcard import + println("L7: " + X) // `X' refers to `Q.X' here + import X._ // `x' and `y' bound by wildcard import + println("L8: " + x) // `x' refers to `Q.X.x' here + object C { + val x = 3 // `x' bound by local definition + println("L12: " + x) // `x' refers to constant `3' here + locally { + import Q.X._ // `x' and `y' bound by wildcard import + println("L14: " + x) // reference to `x' is ambiguous here + import X.y // `y' bound by explicit import + println("L16: " + y) // `y' refers to `Q.X.y' here + locally { + import P.X._ // `x' and `y' bound by wildcard import + val x = "abc" // `x' bound by local definition + println("L19: " + y) // reference to `y' is ambiguous here + println("L20: " + x) // `x' refers to string ``abc'' here + } + } + } + } + } +} diff --git a/tests/pos/i884.scala b/tests/pos/i884.scala new file mode 100644 index 000000000..29e53b9be --- /dev/null +++ b/tests/pos/i884.scala @@ -0,0 +1,4 @@ +import scala.reflect._ + +object `package` { +} diff --git a/tests/pos/overloadedAccess.scala b/tests/pos/overloadedAccess.scala index a2d72f583..10168b61d 100644 --- a/tests/pos/overloadedAccess.scala +++ b/tests/pos/overloadedAccess.scala @@ -14,5 +14,4 @@ object overloadedAccess { val x = f("abc") val y: Int = x } - } diff --git a/tests/pos/typedIdents.scala b/tests/pos/typedIdents.scala deleted file mode 100644 index e99b5a045..000000000 --- a/tests/pos/typedIdents.scala +++ /dev/null @@ -1,34 +0,0 @@ -package P { - object X { val x = 1; val y = 2 } -} -package Q { - object X { val x = true; val y = "" } -} -package P { // `X' bound by package clause - import Console._ // `println' bound by wildcard import - object A { - println("L4: " + X) // `X' refers to `P.X' here - object B { - import Q._ // `X' bound by wildcard import - println("L7: " + X) // `X' refers to `Q.X' here - import X._ // `x' and `y' bound by wildcard import - println("L8: " + x) // `x' refers to `Q.X.x' here - object C { - val x = 3 // `x' bound by local definition - println("L12: " + x) // `x' refers to constant `3' here - locally { - import Q.X._ // `x' and `y' bound by wildcard import - // println("L14: " + x) // reference to `x' is ambiguous here - import X.y // `y' bound by explicit import - println("L16: " + y) // `y' refers to `Q.X.y' here - locally { - val x = "abc" // `x' bound by local definition - import P.X._ // `x' and `y' bound by wildcard import - // println("L19: " + y) // reference to `y' is ambiguous here - println("L20: " + x) // `x' refers to string ``abc'' here - } - } - } - } - } -} diff --git a/tests/pos/typedIdents/PQ.scala b/tests/pos/typedIdents/PQ.scala new file mode 100644 index 000000000..8a5afede0 --- /dev/null +++ b/tests/pos/typedIdents/PQ.scala @@ -0,0 +1,6 @@ +package P { + object X { val x = 1; val y = 2 } +} +package Q { + object X { val x = true; val y = "" } +} -- cgit v1.2.3