summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Constants.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala15
-rw-r--r--test/files/neg/bug700.check4
-rw-r--r--test/files/neg/bug700.scala (renamed from test/files/pos/bug700.scala)0
-rw-r--r--test/files/pos/bug202.scala8
-rw-r--r--test/files/pos/bug697.scala3
-rw-r--r--test/files/pos/bug698.scala12
8 files changed, 33 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 6fe085a54e..b942f73b22 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -273,8 +273,8 @@ trait Parsers requires SyntaxAnalyzer {
case '|' => 2
case '^' => 3
case '&' => 4
- case '<' | '>' => 5
- case '=' | '!' => 6
+ case '=' | '!' => 5
+ case '<' | '>' => 6
case ':' => 7
case '+' | '-' => 8
case '*' | '/' | '%' => 9
diff --git a/src/compiler/scala/tools/nsc/symtab/Constants.scala b/src/compiler/scala/tools/nsc/symtab/Constants.scala
index 38fc822b18..181ab56ef1 100644
--- a/src/compiler/scala/tools/nsc/symtab/Constants.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Constants.scala
@@ -12,6 +12,7 @@ trait Constants requires SymbolTable {
import definitions._;
+ final val NoTag = LITERAL - LITERAL
final val UnitTag = LITERALunit - LITERAL;
final val BooleanTag = LITERALboolean - LITERAL;
final val ByteTag = LITERALbyte - LITERAL;
@@ -27,6 +28,8 @@ trait Constants requires SymbolTable {
final val EnumTag = ClassTag + 1;
final val ArrayTag = EnumTag + 1;
+ def isNumeric(tag: int) = ByteTag <= tag && tag <= DoubleTag
+
case class Constant(value: Any) {
val tag: int =
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
index 32d7fcd800..a19c5799d4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
@@ -16,21 +16,21 @@ abstract class ConstantFolder {
case Apply(Select(Literal(x), op), List(Literal(y))) => foldBinop(op, x, y)
case Select(Literal(x), op) => foldUnop(op, x)
case _ => null
- });
+ })
/** If tree is a constant value that can be converted to type `pt', perform the conversion */
def apply(tree: Tree, pt: Type): Tree = fold(tree, tree.tpe match {
case ConstantType(x) => x convertTo pt
case _ => null
- });
+ })
- private def fold(tree: Tree, compX: =>Constant): Tree =
+ private def fold(tree: Tree, compX: => Constant): Tree =
try {
val x = compX
if (x != null && x.tag != UnitTag) tree setType ConstantType(x)
- else tree;
+ else tree
} catch {
- case _:ArithmeticException => tree // the code will crash at runtime,
+ case _: ArithmeticException => tree // the code will crash at runtime,
// but that is better than the
// compiler itself crashing
}
@@ -55,7 +55,10 @@ abstract class ConstantFolder {
}
private def foldBinop(op: Name, x: Constant, y: Constant): Constant = try {
- val optag = if (x.tag > y.tag) x.tag else y.tag;
+ val optag = if (x.tag == y.tag) x.tag
+ else if (isNumeric(x.tag) && isNumeric(y.tag))
+ if (x.tag > y.tag) x.tag else y.tag
+ else NoTag
optag match {
case BooleanTag =>
op match {
diff --git a/test/files/neg/bug700.check b/test/files/neg/bug700.check
new file mode 100644
index 0000000000..fb3fbb5e1b
--- /dev/null
+++ b/test/files/neg/bug700.check
@@ -0,0 +1,4 @@
+bug700.scala:6 error: method foobar in trait Bar is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'
+ def foobar: unit = super.foobar
+ ^
+one error found
diff --git a/test/files/pos/bug700.scala b/test/files/neg/bug700.scala
index 7477bb54f6..7477bb54f6 100644
--- a/test/files/pos/bug700.scala
+++ b/test/files/neg/bug700.scala
diff --git a/test/files/pos/bug202.scala b/test/files/pos/bug202.scala
deleted file mode 100644
index 087e1ff5d2..0000000000
--- a/test/files/pos/bug202.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-trait C {
- type T;
- def f(x: T): unit;
-}
-
-trait D extends C {
- def f(x: T): unit = super.f(x);
-}
diff --git a/test/files/pos/bug697.scala b/test/files/pos/bug697.scala
new file mode 100644
index 0000000000..6caea418d5
--- /dev/null
+++ b/test/files/pos/bug697.scala
@@ -0,0 +1,3 @@
+object test {
+ val x = 10 == 20 == 30 < 10;
+}
diff --git a/test/files/pos/bug698.scala b/test/files/pos/bug698.scala
new file mode 100644
index 0000000000..a70acae213
--- /dev/null
+++ b/test/files/pos/bug698.scala
@@ -0,0 +1,12 @@
+abstract class Foo
+{
+ val x : Bar
+}
+
+abstract class Bar
+
+object Test
+ extends Foo with Application
+{
+ object x extends Bar
+}