summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-08-04 15:36:09 +0000
committerMartin Odersky <odersky@gmail.com>2003-08-04 15:36:09 +0000
commit5cbecc3b89757f6996c199e73518b8387d4a5a6a (patch)
tree83d6522f8172b62e0bced4c4c312c16939d69f6f
parentf014b416aa6099f9031f60f1ccdb19a9ced74382 (diff)
downloadscala-5cbecc3b89757f6996c199e73518b8387d4a5a6a.tar.gz
scala-5cbecc3b89757f6996c199e73518b8387d4a5a6a.tar.bz2
scala-5cbecc3b89757f6996c199e73518b8387d4a5a6a.zip
*** empty log message ***
-rw-r--r--sources/scala/List.scala2
-rw-r--r--sources/scala/Predef.scala2
-rw-r--r--sources/scala/SeqTrace.scala2
-rw-r--r--sources/scala/Stream.scala4
-rw-r--r--sources/scala/collection/immutable/Queue.scala46
-rw-r--r--sources/scala/collection/mutable/Set.scala2
-rw-r--r--sources/scala/runtime/ScalaRunTime.scala4
-rw-r--r--sources/scalac/ast/parser/Parser.java4
-rw-r--r--sources/scalac/ast/parser/Scanner.java4
-rw-r--r--sources/scalac/ast/parser/Tokens.java20
-rw-r--r--sources/scalac/symtab/Definitions.java4
-rw-r--r--sources/scalac/typechecker/Analyzer.java17
-rw-r--r--sources/scalac/util/Names.java4
-rw-r--r--test/files/pos/exceptions.scala2
-rw-r--r--test/files/run/arrays.scala8
-rw-r--r--test/files/run/iq.scala10
-rw-r--r--test/files/run/lisp.scala27
-rw-r--r--test/pos/exceptions.scala2
18 files changed, 86 insertions, 78 deletions
diff --git a/sources/scala/List.scala b/sources/scala/List.scala
index 4c7112ab3e..e8c661e732 100644
--- a/sources/scala/List.scala
+++ b/sources/scala/List.scala
@@ -263,7 +263,7 @@ trait List[+a] extends Seq[a] {
def print: Unit =
if (isEmpty) java.lang.System.out.println("Nil")
else {
- java.lang.System.out.print(head as java.lang.Object);
+ java.lang.System.out.print(head.asInstanceOf[java.lang.Object]);
java.lang.System.out.print(" :: ");
tail.print
}
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index 35ff71593b..73970c81fc 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -12,7 +12,7 @@ object Predef {
type boolean = scala.Boolean;
type unit = scala.Unit;
- def List[A](x: A*): List[A] = x as List[A];
+ def List[A](x: A*): List[A] = x.asInstanceOf[List[A]];
val List = scala.List;
/*
diff --git a/sources/scala/SeqTrace.scala b/sources/scala/SeqTrace.scala
index ceec585560..6439f8889b 100644
--- a/sources/scala/SeqTrace.scala
+++ b/sources/scala/SeqTrace.scala
@@ -37,7 +37,7 @@ abstract class SeqTrace[A] extends List[Pair[Int,A]] {
// why the f&&k do I need the .as cast ?
def add[A](state: Int, value: A): SeqTraceCons[A] =
- SeqTraceCons[A](state, value, this as SeqTrace[A]);
+ SeqTraceCons[A](state, value, this.asInstanceOf[SeqTrace[A]]);
// this is copied verbatim from List... and SeqList
/*
diff --git a/sources/scala/Stream.scala b/sources/scala/Stream.scala
index 7be860553b..aa7fe82db7 100644
--- a/sources/scala/Stream.scala
+++ b/sources/scala/Stream.scala
@@ -113,7 +113,7 @@ trait Stream[+a] extends Seq[a] {
def print: unit =
if (isEmpty) System.out.println("Stream.empty")
else {
- System.out.print(head as java.lang.Object);
+ System.out.print(head.asInstanceOf[java.lang.Object]);
System.out.print(", ");
tail.print
}
@@ -143,7 +143,7 @@ object Stream {
tlVal
}
def printElems(buf: StringBuffer, prefix: String): StringBuffer = {
- val buf1 = buf.append(prefix).append(hd as java.lang.Object);
+ val buf1 = buf.append(prefix).append(hd.asInstanceOf[java.lang.Object]);
if (tlDefined) printElems(buf1, ", ") else buf1 append ", ?";
}
}
diff --git a/sources/scala/collection/immutable/Queue.scala b/sources/scala/collection/immutable/Queue.scala
index b46b73012d..99171e1497 100644
--- a/sources/scala/collection/immutable/Queue.scala
+++ b/sources/scala/collection/immutable/Queue.scala
@@ -133,31 +133,27 @@ class Queue[+A](in:List[A],out:List[A]) extends Seq[A] {
/** Compares two queues for equality by comparing
* each element in the queues.
*/
- override def equals(o :Any) = {
- /* Make sure o is a Queue. */
- if (o is Queue[Any]) {
- /* o is a queue so we cast it and store it in q. */
- val q:Queue[Any] = o as Queue[Any];
- /* A function that compares the element at
- position index in q with the element at
- the same position in this (queue).
- If they are equal the next element is
- compared.
- */
- def eqe(index: int):Boolean = {
- /* If all elements are compared
- the queues are equal. */
- index >= this.length ||
- /* Otherwise: compare the elements */
- (q.apply(index) == this.apply(index) &&
- /* if they are equal compare the rest. */
- eqe(index+1))
- }
- /* If the length of the ques are the same,
- compare each element, starting at index 0. */
- (q.length == this.length) && eqe(0);
-
- } else false; /* o is not a queue: not equal to this. */
+ override def equals(o :Any) = o match {
+ case q: Queue[Any] =>
+ /* A function that compares the element at
+ position index in q with the element at
+ the same position in this (queue).
+ If they are equal the next element is
+ compared. */
+ def eqe(index: int):Boolean = {
+ /* If all elements are compared
+ the queues are equal. */
+ index >= this.length ||
+ /* Otherwise: compare the elements */
+ (q.apply(index) == this.apply(index) &&
+ /* if they are equal compare the rest. */
+ eqe(index+1))
+ }
+ /* If the length of the ques are the same,
+ compare each element, starting at index 0. */
+ (q.length == this.length) && eqe(0);
+
+ case _ => false; /* o is not a queue: not equal to this. */
}
}
diff --git a/sources/scala/collection/mutable/Set.scala b/sources/scala/collection/mutable/Set.scala
index 158963db40..665befc255 100644
--- a/sources/scala/collection/mutable/Set.scala
+++ b/sources/scala/collection/mutable/Set.scala
@@ -23,7 +23,7 @@ trait Set[A] with scala.collection.Set[A] {
def +=(elem: A): Unit;
def incl(elems: A*): Unit = {
- val ys = elems as List[A];
+ val ys = elems.asInstanceOf[List[A]];
ys foreach { y => +=(y); };
}
diff --git a/sources/scala/runtime/ScalaRunTime.scala b/sources/scala/runtime/ScalaRunTime.scala
index 18bbcb27a7..0b27202399 100644
--- a/sources/scala/runtime/ScalaRunTime.scala
+++ b/sources/scala/runtime/ScalaRunTime.scala
@@ -5,14 +5,14 @@ object ScalaRunTime {
class Try[a](r: scala.runtime.ResultOrException[a]) {
def Catch[b >: a](handler: PartialFunction[Throwable, b]): b =
if (r.exc == null)
- r.result as b
+ r.result.asInstanceOf[b]
else if (/*!(r.exc is NonLocalReturn) && */handler isDefinedAt r.exc)
handler(r.exc)
else
r.exc.throw;
def Finally(handler: Unit): a =
- if (r.exc == null) r.result as a else r.exc.throw;
+ if (r.exc == null) r.result.asInstanceOf[a] else r.exc.throw;
}
def Try[a](def block: a): Try[a] =
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java
index afb5d8abbe..fc544b50d4 100644
--- a/sources/scalac/ast/parser/Parser.java
+++ b/sources/scalac/ast/parser/Parser.java
@@ -867,10 +867,6 @@ public class Parser implements Tokens {
int pos = s.skipToken();
Tree tp = type1();
t = make.Typed(pos, t, tp);
- } else if (s.token == AS || s.token == IS) {
- Name op = (s.token == AS) ? Names.as : Names.is;
- int pos = s.skipToken();
- t = make.TypeApply(pos, make.Select(pos, t, op), new Tree[]{type1()});
}
if (s.token == ARROW) {
t = make.Function(s.skipToken(), convertToParams(t), expr());
diff --git a/sources/scalac/ast/parser/Scanner.java b/sources/scalac/ast/parser/Scanner.java
index 4b070006bc..7ae8840697 100644
--- a/sources/scalac/ast/parser/Scanner.java
+++ b/sources/scalac/ast/parser/Scanner.java
@@ -129,7 +129,7 @@ public class Scanner extends TokenData {
case COMMA: case SEMI: case DOT:
case COLON: case EQUALS: case ARROW:
case LARROW: case SUBTYPE: case SUPERTYPE:
- case HASH: case AT: case AS: case IS:
+ case HASH: case AT:
case RPAREN: case RBRACKET: case RBRACE:
break;
default:
@@ -810,7 +810,6 @@ public class Scanner extends TokenData {
protected void initKeywords() {
enterKeyword("abstract", ABSTRACT);
- enterKeyword("as", AS);
enterKeyword("case", CASE);
enterKeyword("class", CLASS);
enterKeyword("catch", CATCH);
@@ -824,7 +823,6 @@ public class Scanner extends TokenData {
enterKeyword("for", FOR);
enterKeyword("if", IF);
enterKeyword("import", IMPORT);
- enterKeyword("is", IS);
enterKeyword("new", NEW);
enterKeyword("null", NULL);
enterKeyword("object", OBJECT);
diff --git a/sources/scalac/ast/parser/Tokens.java b/sources/scalac/ast/parser/Tokens.java
index 9da23bc7e3..3153d4a78d 100644
--- a/sources/scalac/ast/parser/Tokens.java
+++ b/sources/scalac/ast/parser/Tokens.java
@@ -55,18 +55,16 @@ public interface Tokens {
IMPORT = 46,
PACKAGE = 47,
- AS = 48,
- IS = 49,
- YIELD = 50,
- DO = 51,
- TRAIT = 52,
- SEALED = 53,
+ YIELD = 48,
+ DO = 49,
+ TRAIT = 50,
+ SEALED = 51,
/* THROW = 54, */
- TRY = 55,
- CATCH = 56,
- FINALLY = 57,
- WHILE = 58,
- RETURN = 59,
+ TRY = 53,
+ CATCH = 54,
+ FINALLY = 55,
+ WHILE = 56,
+ RETURN = 57,
/* special symbols */
COMMA = 61,
diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java
index 648e253380..9e269348c6 100644
--- a/sources/scalac/symtab/Definitions.java
+++ b/sources/scalac/symtab/Definitions.java
@@ -318,13 +318,13 @@ public class Definitions {
ANY_CLASS.members().enter(MATCH);
AS = new TermSymbol(
- Position.NOPOS, Names.as, ANY_CLASS, Modifiers.FINAL);
+ Position.NOPOS, Names.asInstanceOf, ANY_CLASS, Modifiers.FINAL);
Symbol tvar = newTypeParameter(AS, ANY_TYPE);
AS.setInfo(Type.PolyType(new Symbol[]{tvar}, tvar.type()));
ANY_CLASS.members().enter(AS);
IS = new TermSymbol(
- Position.NOPOS, Names.is, ANY_CLASS, Modifiers.FINAL);
+ Position.NOPOS, Names.isInstanceOf, ANY_CLASS, Modifiers.FINAL);
IS.setInfo(Type.PolyType(new Symbol[]{newTypeParameter(IS, ANY_TYPE)},
BOOLEAN_TYPE));
ANY_CLASS.members().enter(IS);
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index f9b0935074..8c334efa8c 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -1269,7 +1269,22 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
// this works as for superclass constructor calls the expected
// type `pt' is always AnyType (see transformConstrInvocations).
}
- if (!(owntype instanceof Type.PolyType || owntype.isSubType(pt))) {
+ if (!(owntype instanceof Type.PolyType ||
+ owntype.isSubType(pt))) {
+ switch (tree) {
+ case Literal(Object value):
+ if (value instanceof Integer) {
+ int n = ((Integer) value).intValue();
+ if (pt.symbol() == definitions.BYTE_CLASS &&
+ -128 <= n && n <= 127 ||
+ pt.symbol() == definitions.SHORT_CLASS &&
+ -32768 <= n && n <= 32767 ||
+ pt.symbol() == definitions.CHAR_CLASS &&
+ 0 <= n && n <= 65535) {
+ return tree.setType(pt);
+ }
+ }
+ }
typeError(tree.pos, owntype, pt);
Type.explainTypes(owntype, pt);
tree.type = Type.ErrorType;
diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java
index 8d1ae3964c..c059218230 100644
--- a/sources/scalac/util/Names.java
+++ b/sources/scalac/util/Names.java
@@ -72,7 +72,7 @@ public class Names {
public static final Name Unit = Name.fromString("Unit");
public static final Name While = Name.fromString("While");
public static final Name apply = Name.fromString("apply");
- public static final Name as = Name.fromString("as");
+ public static final Name asInstanceOf = Name.fromString("asInstanceOf");
public static final Name box = Name.fromString("box");
public static final Name elem = Name.fromString("elem");
public static final Name elements = Name.fromString("elements");
@@ -83,7 +83,7 @@ public class Names {
public static final Name getClass = Name.fromString("getClass");
public static final Name hashCode = Name.fromString("hashCode");
public static final Name hasNext = Name.fromString("hasNext");
- public static final Name is = Name.fromString("is");
+ public static final Name isInstanceOf = Name.fromString("isInstanceOf");
public static final Name isDefinedAt = Name.fromString("isDefinedAt");
public static final Name java = Name.fromString("java");
public static final Name java_lang = Name.fromString("java.lang");
diff --git a/test/files/pos/exceptions.scala b/test/files/pos/exceptions.scala
index f28a10d367..2ba15efb4a 100644
--- a/test/files/pos/exceptions.scala
+++ b/test/files/pos/exceptions.scala
@@ -1,6 +1,6 @@
import java.io._;
-object test {
+object Test {
//def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
diff --git a/test/files/run/arrays.scala b/test/files/run/arrays.scala
index 8d375166d3..1100366392 100644
--- a/test/files/run/arrays.scala
+++ b/test/files/run/arrays.scala
@@ -96,8 +96,8 @@ object arrays {
System.out.println();
zarray(0) = false;
- barray(0) = 1 as Byte;
- sarray(0) = 2 as Short;
+ barray(0) = 1.asInstanceOf[Byte];
+ sarray(0) = 2.asInstanceOf[Short];
carray(0) ='3';
iarray(0) = 4;
larray(0) = 5;
@@ -106,8 +106,8 @@ object arrays {
rarray(0) ="8";
zarray(1) = true;
- barray(1) = 2 as Byte;
- sarray(1) = 3 as Short;
+ barray(1) = 2.asInstanceOf[Byte];
+ sarray(1) = 3.asInstanceOf[Short];
carray(1) ='4';
iarray(1) = 5;
larray(1) = 6;
diff --git a/test/files/run/iq.scala b/test/files/run/iq.scala
index f9c55476c7..cb18004ad2 100644
--- a/test/files/run/iq.scala
+++ b/test/files/run/iq.scala
@@ -43,11 +43,11 @@ object iq {
*/
java.lang.System.out.println("q5[5]: " + q5(5));
- val q5c:Queue[char] = Queue.Empty.enqueue(0 as char, 1 as char,
- 2 as char, 3 as char,
- 4 as char, 5 as char,
- 6 as char, 7 as char,
- 8 as char, 9 as char);
+ val q5c:Queue[char] = Queue.Empty.enqueue(0: char, 1: char,
+ 2: char, 3: char,
+ 4: char, 5: char,
+ 6: char, 7: char,
+ 8: char, 9: char);
/* Testing ==
* Expected: q5 == q9: true
* q9 == q5: true
diff --git a/test/files/run/lisp.scala b/test/files/run/lisp.scala
index c8c166a76c..2eb58528ab 100644
--- a/test/files/run/lisp.scala
+++ b/test/files/run/lisp.scala
@@ -288,18 +288,23 @@ object LispAny with Lisp {
def lookup(n: String): Data = lispError("undefined: " + n);
}
- def asList(x: Data): List[Data] =
- if (x is List[Data]) x as List[Data]
- else lispError("malformed list: " + x);
+ def asList(x: Data): List[Data] = x match {
+ case y: List[Data] => y
+ case _ => lispError("malformed list: " + x)
+ }
- def asBoolean(x: Data): boolean =
- if (x == 0) false else true;
+ def asInt(x: Data): int = x match {
+ case y: int => y
+ case _ => lispError("not an integer: " + x)
+ }
- def asInt(x: Data): int =
- if (x is int) x as int else lispError("not an integer: " + x);
+ def asString(x: Data): String = x match {
+ case y: java.lang.String => y
+ case _ => lispError("not a string: " + x)
+ }
- def asString(x: Data): String =
- if (x is java.lang.String) x as java.lang.String else lispError("not a string: " + x);
+ def asBoolean(x: Data): boolean =
+ if (x == 0) false else true;
def normalize(x: Data): Data = x match {
case 'and :: x :: y :: Nil =>
@@ -368,7 +373,7 @@ object LispAny with Lisp {
case y :: ys => " " + lisp2string(y) + list2string(ys)
}
"(" + lisp2string(y) + list2string(ys) + ")"
- case _ => if (x is String) "\"" + x + "\""; else x.toString()
+ case _ => if (x.isInstanceOf[String]) "\"" + x + "\""; else x.toString()
}
def apply(fn: Data, args: List[Data]): Data = fn match {
@@ -452,7 +457,7 @@ class LispUser(lisp: Lisp) {
def run = {
- System.out.println(string2lisp("(lambda (x) (+ (* x x) 1))") as Object);
+ System.out.println(string2lisp("(lambda (x) (+ (* x x) 1))").asInstanceOf[Object]);
System.out.println(lisp2string(string2lisp("(lambda (x) (+ (* x x) 1))")));
System.out.println();
diff --git a/test/pos/exceptions.scala b/test/pos/exceptions.scala
index f28a10d367..2ba15efb4a 100644
--- a/test/pos/exceptions.scala
+++ b/test/pos/exceptions.scala
@@ -1,6 +1,6 @@
import java.io._;
-object test {
+object Test {
//def error[a](x: String):a = new java.lang.RuntimeException(x) throw;