summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-11 15:31:23 +0000
committerPaul Phillips <paulp@improving.org>2010-12-11 15:31:23 +0000
commit933148f71e1254089d036b2428a1c51cb2816c56 (patch)
tree0d5cb5db6d771464756975a493c54e63f41dfeaa
parent262ee3a852f278f97b083a05376de0eab96c805d (diff)
downloadscala-933148f71e1254089d036b2428a1c51cb2816c56.tar.gz
scala-933148f71e1254089d036b2428a1c51cb2816c56.tar.bz2
scala-933148f71e1254089d036b2428a1c51cb2816c56.zip
Turned an assert/compiler crash into an error m...
Turned an assert/compiler crash into an error message. Admittedly the error output is still terrible (the XML positioning looks like it came from an RNG) but more helpful than the crash. Also misc advantage of a handy new method. Closes #4069, no review.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Scanners.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala12
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala6
-rw-r--r--test/files/neg/bug4069.check16
-rw-r--r--test/files/neg/bug4069.scala10
6 files changed, 35 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
index 0835a1b2d0..3322a5a28f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
@@ -77,7 +77,9 @@ trait Scanners extends ScannersCommon {
def resume(lastCode: Int) = {
token = lastCode
- assert(next.token == EMPTY || reporter.hasErrors)
+ if (next.token != EMPTY && !reporter.hasErrors)
+ syntaxError("unexpected end of input: possible missing '}' in XML block")
+
nextToken()
}
diff --git a/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala b/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
index b1be70a54c..2754a7b113 100644
--- a/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
+++ b/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
@@ -581,16 +581,10 @@ abstract class ScalaPrimitives {
val code = getPrimitive(fun)
def elementType = atPhase(currentRun.typerPhase) {
- val arrayParent = tpe :: tpe.parents find {
- case TypeRef(_, sym, _elem :: Nil)
- if (sym == ArrayClass) => true
- case _ => false
+ val arrayParent = tpe :: tpe.parents collectFirst {
+ case TypeRef(_, ArrayClass, elem :: Nil) => elem
}
- if (arrayParent.isEmpty) {
- println(fun.fullName + " : " + tpe :: tpe.baseTypeSeq.toList)
- }
- val TypeRef(_, _, elem :: Nil) = arrayParent.get
- elem
+ arrayParent getOrElse system.error(fun.fullName + " : " + (tpe :: tpe.baseTypeSeq.toList).mkString(", "))
}
code match {
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 1c39e582df..ee0a0c4d81 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -349,10 +349,7 @@ trait Definitions extends reflect.generic.StandardDefinitions {
/** if tpe <: ProductN[T1,...,TN], returns Some(T1,...,TN) else None */
def getProductArgs(tpe: Type): Option[List[Type]] =
- tpe.baseClasses.find(x => isExactProductType(x.tpe)) match {
- case Some(p) => Some(tpe.baseType(p).typeArgs)
- case _ => None
- }
+ tpe.baseClasses collectFirst { case x if isExactProductType(x.tpe) => tpe.baseType(x).typeArgs }
def unapplyUnwrap(tpe:Type) = (tpe match {
case PolyType(_,MethodType(_, res)) => res
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index 5d19d469b5..c2110f104d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -38,10 +38,8 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
private var validCurrentOwner = true
private var accDefs: List[(Symbol, ListBuffer[Tree])] = List()
- private def accDefBuf(clazz: Symbol) = accDefs find (_._1 == clazz) match {
- case Some((_, buf)) => buf
- case None => throw new AssertionError("no acc def buf for "+clazz)
- }
+ private def accDefBuf(clazz: Symbol) =
+ accDefs collectFirst { case (`clazz`, buf) => buf } getOrElse system.error("no acc def buf for "+clazz)
private def transformArgs(args: List[Tree], params: List[Symbol]) =
((args, params).zipped map { (arg, param) =>
diff --git a/test/files/neg/bug4069.check b/test/files/neg/bug4069.check
new file mode 100644
index 0000000000..d3aa8f3992
--- /dev/null
+++ b/test/files/neg/bug4069.check
@@ -0,0 +1,16 @@
+bug4069.scala:7: error: unexpected end of input: possible missing '}' in XML block
+ case 2 =>
+ ^
+bug4069.scala:6: error: Missing closing brace `}' assumed here
+ </div>
+ ^
+bug4069.scala:9: error: in XML literal: in XML content, please use '}}' to express '}'
+ }
+ ^
+bug4069.scala:4: error: I encountered a '}' where I didn't expect one, maybe this tag isn't closed <div>
+ <div>
+ ^
+bug4069.scala:10: error: '}' expected but eof found.
+}
+^
+5 errors found
diff --git a/test/files/neg/bug4069.scala b/test/files/neg/bug4069.scala
new file mode 100644
index 0000000000..80df6ec16d
--- /dev/null
+++ b/test/files/neg/bug4069.scala
@@ -0,0 +1,10 @@
+object ParserBug {
+ 1 match {
+ case 1 =>
+ <div>
+ { 1 match { case 1 => "1"; case 2 => "2" }
+ </div>
+ case 2 =>
+ <div/>
+ }
+} \ No newline at end of file