diff options
author | Martin Odersky <odersky@gmail.com> | 2003-08-04 15:36:09 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-08-04 15:36:09 +0000 |
commit | 5cbecc3b89757f6996c199e73518b8387d4a5a6a (patch) | |
tree | 83d6522f8172b62e0bced4c4c312c16939d69f6f /sources | |
parent | f014b416aa6099f9031f60f1ccdb19a9ced74382 (diff) | |
download | scala-5cbecc3b89757f6996c199e73518b8387d4a5a6a.tar.gz scala-5cbecc3b89757f6996c199e73518b8387d4a5a6a.tar.bz2 scala-5cbecc3b89757f6996c199e73518b8387d4a5a6a.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/List.scala | 2 | ||||
-rw-r--r-- | sources/scala/Predef.scala | 2 | ||||
-rw-r--r-- | sources/scala/SeqTrace.scala | 2 | ||||
-rw-r--r-- | sources/scala/Stream.scala | 4 | ||||
-rw-r--r-- | sources/scala/collection/immutable/Queue.scala | 46 | ||||
-rw-r--r-- | sources/scala/collection/mutable/Set.scala | 2 | ||||
-rw-r--r-- | sources/scala/runtime/ScalaRunTime.scala | 4 | ||||
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 4 | ||||
-rw-r--r-- | sources/scalac/ast/parser/Scanner.java | 4 | ||||
-rw-r--r-- | sources/scalac/ast/parser/Tokens.java | 20 | ||||
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 4 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 17 | ||||
-rw-r--r-- | sources/scalac/util/Names.java | 4 |
13 files changed, 59 insertions, 56 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"); |