summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-01-16 16:17:29 -0800
committerPaul Phillips <paulp@improving.org>2012-01-16 16:52:22 -0800
commit8e9873f550110df8a028c77343154daf79a324df (patch)
tree41bcadcc8730274aed5c52f3a41c3bc866339cdd
parent484af96c6d4a8684a4a1927693fd2485dd64e9ce (diff)
downloadscala-8e9873f550110df8a028c77343154daf79a324df.tar.gz
scala-8e9873f550110df8a028c77343154daf79a324df.tar.bz2
scala-8e9873f550110df8a028c77343154daf79a324df.zip
Improved a cyclic reference error message.
"illegal cyclic reference involving value <import>" not so useful.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala11
-rw-r--r--test/files/neg/cyclics-import.check15
-rw-r--r--test/files/neg/cyclics-import.scala17
-rw-r--r--test/files/neg/t1845.check8
-rw-r--r--test/files/neg/t2870.check8
5 files changed, 52 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
index 02c6e86fde..fe3ceafa2d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
@@ -494,6 +494,11 @@ trait TypeDiagnostics {
def cyclicReferenceMessage(sym: Symbol, tree: Tree) = condOpt(tree) {
case ValDef(_, _, tpt, _) if tpt.tpe == null => "recursive "+sym+" needs type"
case DefDef(_, _, _, _, tpt, _) if tpt.tpe == null => List(cyclicAdjective(sym), sym, "needs result type") mkString " "
+ case Import(expr, selectors) =>
+ ( "encountered unrecoverable cycle resolving import." +
+ "\nNote: this is often due in part to a class depending on a definition nested within its companion." +
+ "\nIf applicable, you may wish to try moving some members into another object."
+ )
}
/** Report a type error.
@@ -508,7 +513,11 @@ trait TypeDiagnostics {
ex match {
case CyclicReference(sym, info: TypeCompleter) =>
- contextError(ex.pos, cyclicReferenceMessage(sym, info.tree) getOrElse ex.getMessage())
+ val pos = info.tree match {
+ case Import(expr, _) => expr.pos
+ case _ => ex.pos
+ }
+ contextError(pos, cyclicReferenceMessage(sym, info.tree) getOrElse ex.getMessage())
if (sym == ObjectClass)
throw new FatalError("cannot redefine root "+sym)
diff --git a/test/files/neg/cyclics-import.check b/test/files/neg/cyclics-import.check
new file mode 100644
index 0000000000..ef355fab0a
--- /dev/null
+++ b/test/files/neg/cyclics-import.check
@@ -0,0 +1,15 @@
+cyclics-import.scala:1: error: encountered unrecoverable cycle resolving import.
+Note: this is often due in part to a class depending on a definition nested within its companion.
+If applicable, you may wish to try moving some members into another object.
+import User.UserStatus._
+ ^
+cyclics-import.scala:12: error: not found: type Value
+ type UserStatus = Value
+ ^
+cyclics-import.scala:14: error: not found: value Value
+ val Active = Value("1")
+ ^
+cyclics-import.scala:15: error: not found: value Value
+ val Disabled = Value("2")
+ ^
+four errors found
diff --git a/test/files/neg/cyclics-import.scala b/test/files/neg/cyclics-import.scala
new file mode 100644
index 0000000000..7b510b58e2
--- /dev/null
+++ b/test/files/neg/cyclics-import.scala
@@ -0,0 +1,17 @@
+import User.UserStatus._
+
+class User {
+ var id: Int = 0
+ var email: String = null
+ var password: String = null
+ var userStatus: UserStatus = null
+}
+
+object User {
+ object UserStatus extends Enumeration {
+ type UserStatus = Value
+
+ val Active = Value("1")
+ val Disabled = Value("2")
+ }
+}
diff --git a/test/files/neg/t1845.check b/test/files/neg/t1845.check
index 7c0bddbc20..a6c82f5659 100644
--- a/test/files/neg/t1845.check
+++ b/test/files/neg/t1845.check
@@ -1,4 +1,6 @@
-t1845.scala:9: error: illegal cyclic reference involving value <import>
- val lexical = new StdLexical
- ^
+t1845.scala:6: error: encountered unrecoverable cycle resolving import.
+Note: this is often due in part to a class depending on a definition nested within its companion.
+If applicable, you may wish to try moving some members into another object.
+ import lexical._
+ ^
one error found
diff --git a/test/files/neg/t2870.check b/test/files/neg/t2870.check
index 72bc0d98a1..ab962d48c8 100644
--- a/test/files/neg/t2870.check
+++ b/test/files/neg/t2870.check
@@ -1,7 +1,9 @@
t2870.scala:1: error: not found: type Jar (similar: Jars)
class Jars(jar: Jar)
^
-t2870.scala:6: error: illegal cyclic reference involving value <import>
- val scala = fromClasspathString(javaClassPath)
- ^
+t2870.scala:4: error: encountered unrecoverable cycle resolving import.
+Note: this is often due in part to a class depending on a definition nested within its companion.
+If applicable, you may wish to try moving some members into another object.
+ import scala.util.Properties.javaClassPath
+ ^
two errors found