summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala12
-rw-r--r--test/files/neg/bug284.check8
-rw-r--r--test/files/neg/bug284.scala6
-rw-r--r--test/files/pos/bug284.scala5
4 files changed, 30 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index b8b8d1bffb..e4a042325c 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -796,8 +796,18 @@ trait Parsers extends NewScanners with MarkupParsers {
}
newLineOptWhenFollowedBy(LBRACE)
atPos(pos) {
- if (inToken == LBRACE)
+ if (inToken == LBRACE) {
+ // Warn if they are attempting to refine Unit; we can't be certain it's
+ // scala.Unit they're refining because at this point all we have is an
+ // identifier, but at a later stage we lose the ability to tell an empty
+ // refinement from no refinement at all. See bug #284.
+ for (Ident(name) <- ts) name.toString match {
+ case "Unit" | "scala.Unit" =>
+ warning("Detected apparent refinement of Unit; are you missing an '=' sign?")
+ case _ =>
+ }
CompoundTypeTree(Template(ts.toList, emptyValDef, refinement()))
+ }
else
makeIntersectionTypeTree(ts.toList)
}
diff --git a/test/files/neg/bug284.check b/test/files/neg/bug284.check
new file mode 100644
index 0000000000..7e54672365
--- /dev/null
+++ b/test/files/neg/bug284.check
@@ -0,0 +1,8 @@
+bug284.scala:2: warning: Detected apparent refinement of Unit; are you missing an '=' sign?
+ def f1(a: T): Unit { }
+ ^
+bug284.scala:6: error: eof expected but '}' found.
+}
+^
+one warning found
+one error found
diff --git a/test/files/neg/bug284.scala b/test/files/neg/bug284.scala
new file mode 100644
index 0000000000..c1817466b5
--- /dev/null
+++ b/test/files/neg/bug284.scala
@@ -0,0 +1,6 @@
+trait B[T] {
+ def f1(a: T): Unit { }
+ def f2(a: T): Unit
+ def f3(a: T) { }
+ }
+} \ No newline at end of file
diff --git a/test/files/pos/bug284.scala b/test/files/pos/bug284.scala
new file mode 100644
index 0000000000..b5879fb3fe
--- /dev/null
+++ b/test/files/pos/bug284.scala
@@ -0,0 +1,5 @@
+trait B[T] {
+ def f1(a: T): Unit { }
+ def f2(a: T): Unit
+ def f3(a: T) { }
+} \ No newline at end of file