aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2017-04-11 20:56:55 +0200
committerGitHub <noreply@github.com>2017-04-11 20:56:55 +0200
commit10a1300b7599407a7c6078244c4b7692e339b39f (patch)
treeee615b89facfa8f4e658952b6f66acc4b211e88d
parentd63191d1d68a7de0bc622356b5af1599b25cbf25 (diff)
parent552d85626aabab273213622df14544f154fbc4ca (diff)
downloaddotty-10a1300b7599407a7c6078244c4b7692e339b39f.tar.gz
dotty-10a1300b7599407a7c6078244c4b7692e339b39f.tar.bz2
dotty-10a1300b7599407a7c6078244c4b7692e339b39f.zip
Merge pull request #2225 from dotty-staging/fix-#2192
Fix #2212: Avoid imports in the wrong namespace
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Typer.scala48
-rw-r--r--tests/pos/i2212.scala19
-rw-r--r--tests/run/t5857.scala5
3 files changed, 43 insertions, 29 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index ba55dfe30..4bf938fd4 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -179,6 +179,20 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
previous
}
+ def selection(imp: ImportInfo, name: Name) =
+ if (imp.sym.isCompleting) {
+ ctx.warning(i"cyclic ${imp.sym}, ignored", tree.pos)
+ NoType
+ } else if (unimported.nonEmpty && unimported.contains(imp.site.termSymbol))
+ NoType
+ else {
+ val pre = imp.site
+ val denot = pre.member(name).accessibleFrom(pre)(refctx)
+ // Pass refctx so that any errors are reported in the context of the
+ // reference instead of the
+ if (reallyExists(denot)) pre.select(name, denot) else NoType
+ }
+
/** The type representing a named import with enclosing name when imported
* from given `site` and `selectors`.
*/
@@ -194,25 +208,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
found
}
- def selection(name: Name) =
- if (imp.sym.isCompleting) {
- ctx.warning(i"cyclic ${imp.sym}, ignored", tree.pos)
- NoType
- }
- else if (unimported.nonEmpty && unimported.contains(imp.site.termSymbol))
- NoType
- else {
- // Pass refctx so that any errors are reported in the context of the
- // reference instead of the
- checkUnambiguous(selectionType(imp.site, name, tree.pos)(refctx))
- }
+ def unambiguousSelection(name: Name) =
+ checkUnambiguous(selection(imp, name))
selector match {
case Thicket(fromId :: Ident(Name) :: _) =>
val Ident(from) = fromId
- selection(if (name.isTypeName) from.toTypeName else from)
+ unambiguousSelection(if (name.isTypeName) from.toTypeName else from)
case Ident(Name) =>
- selection(name)
+ unambiguousSelection(name)
case _ =>
recur(rest)
}
@@ -225,18 +229,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
/** The type representing a wildcard import with enclosing name when imported
* from given import info
*/
- def wildImportRef(imp: ImportInfo)(implicit ctx: Context): Type = {
- if (imp.isWildcardImport) {
- val pre = imp.site
- if (!unimported.contains(pre.termSymbol) &&
- !imp.excluded.contains(name.toTermName) &&
- name != nme.CONSTRUCTOR) {
- val denot = pre.member(name).accessibleFrom(pre)(refctx)
- if (reallyExists(denot)) return pre.select(name, denot)
- }
- }
- NoType
- }
+ def wildImportRef(imp: ImportInfo)(implicit ctx: Context): Type =
+ if (imp.isWildcardImport && !imp.excluded.contains(name.toTermName) && name != nme.CONSTRUCTOR)
+ selection(imp, name)
+ else NoType
/** Is (some alternative of) the given predenotation `denot`
* defined in current compilation unit?
diff --git a/tests/pos/i2212.scala b/tests/pos/i2212.scala
new file mode 100644
index 000000000..416c8ca04
--- /dev/null
+++ b/tests/pos/i2212.scala
@@ -0,0 +1,19 @@
+package object squants {
+ type Time = squants.time.Time
+}
+package squants.time {
+ class Time
+ object Time { def x = 2 }
+}
+package squants.velocity {
+ import squants.time._ // <-- imports `Time` value
+ import squants.Time // <-- imports type alias
+ object Velocity { Time.x }
+}
+
+import scala.math.BigDecimal.RoundingMode
+import scala.math.BigDecimal.RoundingMode.RoundingMode
+
+object Money {
+ def foo(round: RoundingMode = RoundingMode.HALF_EVEN): Int = ???
+}
diff --git a/tests/run/t5857.scala b/tests/run/t5857.scala
index eabf5dc86..fe67a7546 100644
--- a/tests/run/t5857.scala
+++ b/tests/run/t5857.scala
@@ -36,10 +36,9 @@ object Test {
b
}
- // whatever it is, it should be less than, say, 250ms
+ // whatever it is, it should be less than, say, 1000ms
// if `max` involves traversal, it takes over 5 seconds on a 3.2GHz i7 CPU
//println(exectime)
- assert(exectime < 250, exectime)
+ assert(exectime < 1000, exectime)
}
-
}