summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-03-18 11:19:21 +0000
committerMartin Odersky <odersky@gmail.com>2003-03-18 11:19:21 +0000
commit31b5dceeb144c7aa99aa153e4184cbb3b45110e0 (patch)
tree3ac5d7375b94b31ee0727f0a4999adb6298fe179 /sources
parentbbea05c3f79c1135c30c075545ffa604fdf7b68d (diff)
downloadscala-31b5dceeb144c7aa99aa153e4184cbb3b45110e0.tar.gz
scala-31b5dceeb144c7aa99aa153e4184cbb3b45110e0.tar.bz2
scala-31b5dceeb144c7aa99aa153e4184cbb3b45110e0.zip
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/$colon$colon.scala4
-rw-r--r--sources/scala/List.scala8
-rw-r--r--sources/scala/Nil.scala2
-rw-r--r--sources/scala/Predef.scala16
-rw-r--r--sources/scalac/ast/parser/Parser.java34
-rw-r--r--sources/scalac/typechecker/Analyzer.java7
6 files changed, 40 insertions, 31 deletions
diff --git a/sources/scala/$colon$colon.scala b/sources/scala/$colon$colon.scala
index be2baedf5e..6eabdfda30 100644
--- a/sources/scala/$colon$colon.scala
+++ b/sources/scala/$colon$colon.scala
@@ -4,9 +4,9 @@ package scala {
*
*/
final case class ::[b](hd: b, tl: List[b]) extends List[b] with {
- def isEmpty = False;
+ def isEmpty = false;
def head = hd;
def tail = tl;
- override def toString(): String = mkString("[", ",", "]");
+ override def toString(): String = mkString("List(", ",", ")");
}
}
diff --git a/sources/scala/List.scala b/sources/scala/List.scala
index 66f6cea807..d80a13e273 100644
--- a/sources/scala/List.scala
+++ b/sources/scala/List.scala
@@ -263,7 +263,7 @@ trait List[a] extends Seq[a] {
* <code>sep</code>.
* <p>
* Ex: <br>
- * <code>[1, 2, 3].mkString("(", "; ", ")") = "(1; 2; 3)"</code>
+ * <code>List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"</code>
* @param start starting string.
* @param sep separator string.
* @param end ending string.
@@ -345,9 +345,9 @@ trait List[a] extends Seq[a] {
module List {
- def range(lo: Int, hi: Int): List[Int] =
- if (lo > hi) scala.Predef.List()
- else lo :: range(lo + 1, hi);
+ def range(from: Int, end: Int): List[Int] =
+ if (from >= end) scala.Predef.List()
+ else from :: range(from + 1, end);
}
diff --git a/sources/scala/Nil.scala b/sources/scala/Nil.scala
index 508440b7e7..4f835dbd66 100644
--- a/sources/scala/Nil.scala
+++ b/sources/scala/Nil.scala
@@ -7,7 +7,7 @@ package scala {
def isEmpty = True;
def head: c = error("head of empty list");
def tail: List[c] = error("tail of empty list");
- override def toString(): String = "[]";
+ override def toString(): String = "List()";
}
}
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index 456847e08e..e93841f6c1 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -2,21 +2,27 @@ package scala;
module Predef {
+ type byte = scala.Byte;
+ type short = scala.Short;
+ type char = scala.Char;
+ type int = scala.Int;
+ type long = scala.Long;
+ type float = scala.Float;
+ type double = scala.Double;
+ type boolean = scala.Boolean;
+ type unit = scala.Unit;
+
val True = Boolean.True;
val False = Boolean.False;
- val List = scala.List;
-
def List[a](x: a*): List[a] = x as List[a];
+ val List = scala.List;
def error[err](x: String):err = new java.lang.RuntimeException(x).throw;
def try[a](def block: a): Except[a] =
new Except(scala.runtime.ResultOrException.tryBlock(block));
- def range(lo: Int, hi: Int): List[Int] =
- if (lo > hi) List() else lo :: range(lo + 1, hi);
-
def while(def condition: Boolean)(def command: Unit): Unit =
if (condition) {
command; while(condition)(command)
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java
index 48c9689901..934652e638 100644
--- a/sources/scalac/ast/parser/Parser.java
+++ b/sources/scalac/ast/parser/Parser.java
@@ -549,7 +549,7 @@ public class Parser implements Tokens {
return t;
}
- /** Type1 ::= SimpleType {with SimpleType} [with Refinement]
+ /** Type1 ::= SimpleType {with SimpleType} [Refinement]
*/
Tree type1() {
int pos = s.pos;
@@ -559,10 +559,7 @@ public class Parser implements Tokens {
ts.append(t);
while (s.token == WITH) {
s.nextToken();
- if (s.token == LBRACE)
- return make.CompoundType(pos, ts.toArray(), refinement());
- else
- ts.append(simpleType());
+ ts.append(simpleType());
}
return make.CompoundType(pos, ts.toArray(), Tree.EMPTY_ARRAY);
} else {
@@ -650,7 +647,7 @@ public class Parser implements Tokens {
return ts.toArray();
}
- /** Expr ::= [Bindings `=>'] Expr
+ /** Expr ::= Bindings `=>' Expr
* | if `(' Expr `)' Expr [[`;'] else Expr]
* | for `(' Enumerators `)' [do | yield] Expr
* | Designator `=' Expr
@@ -658,6 +655,7 @@ public class Parser implements Tokens {
* | PostfixExpr [`:' Type1 | as Type1 | is Type1]
* Bindings ::= Id [`:' Type1]
* | `(' [Binding {`,' Binding}] `)'
+ * Binding ::= Id [`:' Type]
*/
Tree expr() {
if (s.token == IF) {
@@ -1423,8 +1421,7 @@ public class Parser implements Tokens {
}
}
- /** FunDef ::= Id [TypeParamClause] {ParamClause} [`:' Type]
- * (`=' Expr | BlockExpr)
+ /** FunDef ::= Id [TypeParamClause] {ParamClause} [`:' Type] `=' Expr
* FunSig ::= Id [TypeParamClause] {ParamClause} `:' Type
*/
Tree funDefOrSig(int mods) {
@@ -1444,8 +1441,7 @@ public class Parser implements Tokens {
tparams, vparams, restype, Tree.Empty);
}
- /* ConstrDef ::= Id [TypeParamClause] [ParamClause] [`:' Type]
- * (`=' Constr | `=' BlockConstr | BlockConstr)
+ /* ConstrDef ::= Id [TypeParamClause] [ParamClause] [`:' Type] `=' (Constr | BlockConstr)
*/
Tree constrDefOrSig(int mods) {
int pos = s.pos;
@@ -1507,14 +1503,18 @@ public class Parser implements Tokens {
s.pos, mods, ident(), typedOpt(), classTemplate());
}
- /** ClassTemplate ::= extends Template
- * | [TemplateBody]
+ /** ClassTemplate ::= [`extends' Constr] {`with' Constr} [TemplateBody]
*/
Template classTemplate() {
int pos = s.pos;
if (s.token == EXTENDS) {
s.nextToken();
return template();
+ } else if (s.token == WITH) {
+ s.nextToken();
+ TreeList parents = new TreeList();
+ parents.append(scalaDot(pos, Names.Object.toConstrName()));
+ return template(parents);
} else if (s.token == LBRACE) {
return (Template)make.Template(pos,
new Tree[]{scalaDot(pos, Names.Object.toConstrName())},
@@ -1537,15 +1537,15 @@ public class Parser implements Tokens {
/** Template ::= Constr {`with' Constr} [TemplateBody]
*/
Template template() {
+ return template(new TreeList());
+ }
+
+ Template template(TreeList parents) {
int pos = s.pos;
- TreeList parents = new TreeList();
parents.append(constr());
while (s.token == WITH) {
s.nextToken();
- if (s.token == LBRACE)
- return (Template)make.Template(pos, parents.toArray(), templateBody());
- else
- parents.append(constr());
+ parents.append(constr());
}
Tree[] stats = (s.token == LBRACE) ? templateBody() : Tree.EMPTY_ARRAY;
return (Template)make.Template(pos, parents.toArray(), stats);
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 44059d4066..5e2be22796 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -312,14 +312,17 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
if (parents.length == 0 || !checkClassType(constrs[0].pos, parents[0])) return;
for (int i = 0; i < parents.length; i++) {
if (!checkClassType(constrs[i].pos, parents[i])) return;
- if (1 <= i) {
+ Symbol bsym = parents[i].symbol();
+ if (i == 0) {
+ if ((bsym.flags & INTERFACE) != 0)
+ error(constrs[0].pos, "superclass may not be a Java interface");
+ } else {
Type[] grandparents = parents[i].parents();
if (grandparents.length > 0 &&
!parents[0].isSubType(grandparents[0]))
error(constrs[i].pos, "illegal inheritance;\n " + parents[0] +
" does not conform to " + parents[i] + "'s supertype");
}
- Symbol bsym = parents[i].symbol();
if ((bsym.flags & FINAL) != 0) {
// are we in same scope as base type definition?
Scope.Entry e = context.scope.lookupEntry(bsym.name);