summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/reference/ScalaReference.tex42
-rw-r--r--sources/meta/scalac/ast/Tree.java12
-rw-r--r--sources/scala/Predef.scala2
-rwxr-xr-xsources/scala/collection/immutable/GBTree.scala2
-rw-r--r--sources/scala/runtime/ScalaRunTime.scala4
-rw-r--r--sources/scalac/ast/TreeGen.java30
-rw-r--r--sources/scalac/ast/parser/Parser.java12
-rw-r--r--sources/scalac/ast/parser/Scanner.java1
-rw-r--r--sources/scalac/ast/parser/Tokens.java2
-rw-r--r--sources/scalac/symtab/Definitions.java11
-rw-r--r--sources/scalac/symtab/Symbol.java21
-rw-r--r--sources/scalac/symtab/SymbolTablePrinter.java6
-rw-r--r--sources/scalac/symtab/classfile/UnPickle.java8
-rw-r--r--sources/scalac/transformer/Erasure.java17
-rw-r--r--sources/scalac/transformer/LambdaLift.java8
-rw-r--r--sources/scalac/typechecker/Analyzer.java22
-rw-r--r--sources/scalac/typechecker/DeSugarize.java114
-rw-r--r--sources/scalac/util/Names.java1
-rw-r--r--test/files/pos/simplelists.scala2
-rw-r--r--test/pos/simplelists.scala2
20 files changed, 170 insertions, 149 deletions
diff --git a/doc/reference/ScalaReference.tex b/doc/reference/ScalaReference.tex
index 195922c454..bee684971a 100644
--- a/doc/reference/ScalaReference.tex
+++ b/doc/reference/ScalaReference.tex
@@ -129,8 +129,8 @@ do else extends false final
finally for if import new
null object override package private
protected return sealed super this
-trait try true type val
-var while with yield
+throw trait try true type
+val var while with yield
_ : = => <- <: >: # @
\end{lstlisting}
@@ -1767,9 +1767,9 @@ The \code{override} modifier applies to class member definitions. It
is mandatory for member definitions that override some other
non-abstract member definition in a super- or mixin-class. If an
\code{override} modifier is given, there must be at least one
-overridden member definition. Furthermore, the overridden definition
-must be concrete (\sref{sec:members}), unless the class containing the
-overriding member is abstract.
+overridden member definition. Furthermore, at least one overridden
+definition must be concrete (\sref{sec:members}), unless the class
+containing the overriding member is abstract.
\item
The \code{abstract} modifier is used in class definitions. It is
mandatory if the class has abstract members, or if the class has
@@ -1951,9 +1951,16 @@ If a class definition is prefixed with \code{case}, the class is said
to be a {\em case class}. The primary constructor of a case class may
be used in a constructor pattern (\sref{sec:patterns}). That
constructor may not have any value parameters which are prefixed by
-\code{def}. None of the base classes of a case class may be a case
-class. Furthermore, no type may have two different case classes among
-its base types.
+\code{def}. The following three restrictions ensure efficient pattern
+matching for case classes.
+\begin{enumerate}
+\item None of the base classes of a case class may be a case
+class.
+\item No type may have two different case classes among its base types.
+\item A case class may not inherit indirectly from a
+\lstlinline@sealed@ class. That is, if a base class $b$ of a case class $c$
+is marked \lstineline@sealed@, then $b$ must be a parent class of $c$.
+\end{enumerate}
A case class definition of ~\lstinline@$c$[$\tps\,$]($ps\,$)@~ with type
parameters $\tps$ and value parameters $ps$ implicitly
@@ -2192,6 +2199,8 @@ module FileSystem with {
| while '(' Expr ')' Expr
| do Expr [`;'] while `(' Expr ')'
| for `(' Enumerators `)' (do | yield) Expr
+ | return [Expr]
+ | throw Expr
| [SimpleExpr `.'] id `=' Expr
| SimpleExpr ArgumentExpr `=' Expr
| PostfixExpr [`:' Type1]
@@ -3591,11 +3600,8 @@ final class Double extends AnyVal with Ord {
def / (that: Double): Double // double division
def % (that: Double): Double // double remainder
- def equals(that: Double): Boolean //double equality
- def equals(that: Any) = that match {
- case x: Double => equals(x)
- case _ => false
- }
+ def == (that: Double): Boolean // double equality
+ def != (that: Double): Boolean // double inequality
def < (that: Double): Boolean // double less
def > (that: Double): Boolean // double greater
def <= (that: Double): Boolean // double less or equals
@@ -3619,12 +3625,10 @@ final class Float extends Double with {
def asByte: Byte \>// convert to Byte
def + (that: Double): Double = asDouble + that
- def + (that: Float): Double // float addition
+ def + (that: Float): Double \>// float addition
/* analogous for -, *, /, % */
- def equals(that: Double): Boolean = asDouble equals that
- def equals(that: Float): Boolean = // float equality
- def equals(that: Any): Boolean = super equals that
+ def == (that: Double): Boolean = asDouble == that
def == (that: Float): Boolean \>// float equality
/* analogous for !=, <, >, <=, >= */
@@ -3707,7 +3711,7 @@ class Int extends Long with {
\label{sec:cls-boolean}
\begin{lstlisting}
-abstract final class Boolean extends AnyVal with Ord with {
+abstract sealed class Boolean extends AnyVal with {
def ifThenElse[a](def t: a)(def e: a): a
def ifThen(def t: Unit): Unit = ifThenElse(t)()
@@ -4100,6 +4104,8 @@ grammar.
| try `{' block `}' [catch Expr] [finally Expr]
| do Expr [`;'] while `(' Expr ')'
| for `(' Enumerators `)' (do | yield) Expr
+ | return [Expr]
+ | throw Expr
| [SimpleExpr `.'] id `=' Expr
| SimpleExpr ArgumentExpr `=' Expr
| PostfixExpr [`:' Type1]
diff --git a/sources/meta/scalac/ast/Tree.java b/sources/meta/scalac/ast/Tree.java
index 07d0377fa2..b1af55a774 100644
--- a/sources/meta/scalac/ast/Tree.java
+++ b/sources/meta/scalac/ast/Tree.java
@@ -91,6 +91,8 @@ public class Tree {
n_Assign = node("Assign" , Term, NoSym),
n_If = node("If" , Term, NoSym),
n_Switch = node("Switch" , Term, NoSym),
+ n_Return = node("Return" , Term, HasSym),
+ n_Throw = node("Throw" , Term, NoSym),
n_New = node("New" , Term, NoSym),
n_Typed = node("Typed" , Term, NoSym),
n_TypeApply = node("TypeApply" , Term, NoSym),
@@ -274,6 +276,16 @@ public class Tree {
addField(t_TermTrees, "bodies").
addField(t_TermTree, "otherwise");
+ n_Return.
+ setDescription("Return").
+ setRange(Phase.PARSER, Phase.END).
+ addField(t_TermTree, "expr");
+
+ n_Throw.
+ setDescription("Throw").
+ setRange(Phase.PARSER, Phase.ANALYZER).
+ addField(t_TermTree, "expr");
+
n_New.
setDescription("Instantiation").
setRange(Phase.PARSER, Phase.END).
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index 21d97e653a..ad2cb8e7a5 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -29,7 +29,7 @@ object Predef {
}
*/
- def error(x: String): All = new java.lang.RuntimeException(x).throw;
+ def error(x: String): All = throw new java.lang.RuntimeException(x);
def exit: scala.Unit = System.exit(0);
diff --git a/sources/scala/collection/immutable/GBTree.scala b/sources/scala/collection/immutable/GBTree.scala
index edceffa535..39cafff0cc 100755
--- a/sources/scala/collection/immutable/GBTree.scala
+++ b/sources/scala/collection/immutable/GBTree.scala
@@ -242,7 +242,7 @@ class GBTree[A <: Ord[A], B]() with scala.collection.immutable.Map[A, B, GBTree[
case Nil() =>
ITree(Node(key, value, Nil(), Nil()));
case _ =>
- (new KeyExists(key)).throw;
+ throw new KeyExists(key);
}
}
diff --git a/sources/scala/runtime/ScalaRunTime.scala b/sources/scala/runtime/ScalaRunTime.scala
index 0b27202399..8dd8a2ca1e 100644
--- a/sources/scala/runtime/ScalaRunTime.scala
+++ b/sources/scala/runtime/ScalaRunTime.scala
@@ -9,10 +9,10 @@ object ScalaRunTime {
else if (/*!(r.exc is NonLocalReturn) && */handler isDefinedAt r.exc)
handler(r.exc)
else
- r.exc.throw;
+ throw r.exc;
def Finally(handler: Unit): a =
- if (r.exc == null) r.result.asInstanceOf[a] else r.exc.throw;
+ if (r.exc == null) r.result.asInstanceOf[a] else throw r.exc;
}
def Try[a](def block: a): Try[a] =
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index e3c2315005..751e78044d 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -21,7 +21,7 @@ import Tree.*;
* @author Martin Odersky, Christine Roeckl
* @version 1.0
*/
-public class TreeGen implements Kinds, Modifiers {
+public class TreeGen implements Kinds, Modifiers, TypeTags {
/********************************************************************************/
/********************************************************************************/
@@ -185,6 +185,34 @@ public class TreeGen implements Kinds, Modifiers {
return make.Literal(pos, new Integer(value)).setType(definitions.INT_TYPE);
}
+ /** Build a default zero value according to type
+ */
+ public Tree mkDefaultValue(int pos, Type tp) {
+ if (tp.isSubType(definitions.ANYREF_TYPE)) {
+ return Ident(pos, definitions.NULL);
+ } else {
+ switch (tp.unbox()) {
+ case UnboxedType(BOOLEAN):
+ return mkBooleanLit(pos, false);
+ case UnboxedType(BYTE):
+ case UnboxedType(SHORT):
+ case UnboxedType(CHAR):
+ case UnboxedType(INT):
+ return mkIntLit(pos, 0);
+ case UnboxedType(LONG):
+ return make.Literal(pos, new Long(0)).setType(definitions.LONG_TYPE);
+ case UnboxedType(FLOAT):
+ return make.Literal(pos, new Float(0)).setType(definitions.FLOAT_TYPE);
+ case UnboxedType(DOUBLE):
+ return make.Literal(pos, new Double(0)).setType(definitions.DOUBLE_TYPE);
+ case UnboxedType(UNIT):
+ return Block(pos, Tree.EMPTY_ARRAY);
+ default:
+ return Ident(pos, definitions.ZERO);
+ }
+ }
+ }
+
/** Build a tree to be used as a base class constructor for a template.
*/
public Tree mkParentConstr(int pos, Type parentType, Tree[] parentArgs) {
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java
index af165b22ea..7a6cd2b3db 100644
--- a/sources/scalac/ast/parser/Parser.java
+++ b/sources/scalac/ast/parser/Parser.java
@@ -159,7 +159,7 @@ public class Parser implements Tokens {
case SYMBOLLIT: case TRUE: case FALSE: case NULL: case IDENTIFIER:
case THIS: case SUPER: case IF:
case FOR: case NEW: case USCORE:
- case TRY: case WHILE: case DO:
+ case TRY: case WHILE: case DO: case RETURN: case THROW:
case LPAREN: case LBRACE:
return true;
default:
@@ -812,6 +812,8 @@ public class Parser implements Tokens {
* | while `(' Expr `)' Expr
* | do Expr [`;'] while `(' Expr `)'
* | for `(' Enumerators `)' (do | yield) Expr
+ * | throw Expr
+ * | return [Expr]
* | [SimpleExpr `.'] Id `=' Expr
* | SimpleExpr ArgumentExprs `=' Expr
* | PostfixExpr [`:' Type1 | as Type1 | is Type1]
@@ -885,6 +887,14 @@ public class Parser implements Tokens {
} else {
return syntaxError("`do' or `yield' expected", true);
}
+ } else if (s.token == RETURN) {
+ int pos = s.skipToken();
+ Tree e = (isExprIntro()) ? expr()
+ : make.Block(pos, Tree.EMPTY_ARRAY);
+ return make.Return(pos, e);
+ } else if (s.token == THROW) {
+ int pos = s.skipToken();
+ return make.Throw(pos, expr());
// } else if (s.token == ARROW) {
// return make.Function(s.skipToken(), new ValDef[]{}, expr());
} else {
diff --git a/sources/scalac/ast/parser/Scanner.java b/sources/scalac/ast/parser/Scanner.java
index 7ae8840697..62109eacb0 100644
--- a/sources/scalac/ast/parser/Scanner.java
+++ b/sources/scalac/ast/parser/Scanner.java
@@ -834,6 +834,7 @@ public class Scanner extends TokenData {
enterKeyword("sealed", SEALED);
enterKeyword("super", SUPER);
enterKeyword("this", THIS);
+ enterKeyword("throw", THROW);
enterKeyword("trait", TRAIT);
enterKeyword("true", TRUE);
enterKeyword("try", TRY);
diff --git a/sources/scalac/ast/parser/Tokens.java b/sources/scalac/ast/parser/Tokens.java
index 3153d4a78d..485ce6a465 100644
--- a/sources/scalac/ast/parser/Tokens.java
+++ b/sources/scalac/ast/parser/Tokens.java
@@ -59,7 +59,7 @@ public interface Tokens {
DO = 49,
TRAIT = 50,
SEALED = 51,
- /* THROW = 54, */
+ THROW = 52,
TRY = 53,
CATCH = 54,
FINALLY = 55,
diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java
index 1cf278c6c0..ac4d38e261 100644
--- a/sources/scalac/symtab/Definitions.java
+++ b/sources/scalac/symtab/Definitions.java
@@ -54,6 +54,10 @@ public class Definitions {
*/
public final Symbol NULL;
+ /** the zero value (a default null for type variables with bound Any)
+ */
+ public final Symbol ZERO;
+
/** the scala.Any class
*/
public final Symbol ANY_CLASS;
@@ -232,6 +236,7 @@ public class Definitions {
// the scala.ANYVAL class
ANYVAL_CLASS = getClass(Names.scala_AnyVal);
+ ANYVAL_CLASS.initialize();
ANYVAL_CLASS.flags |= Modifiers.SEALED;
ANYVAL_TYPE = ANYVAL_CLASS.typeConstructor();
@@ -381,6 +386,12 @@ public class Definitions {
Position.NOPOS, Names.null_, ROOT_CLASS, 0);
NULL.setInfo(ALLREF_TYPE);
ROOT.members().enter(NULL);
+
+ // add a null value to the root scope
+ ZERO = new TermSymbol(
+ Position.NOPOS, Names.ZERO, ROOT_CLASS, 0);
+ ZERO.setInfo(ALL_TYPE);
+ ROOT.members().enter(ZERO);
}
private Symbol newParameter(Symbol owner, Type tp) {
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 28772e6bc5..d0494f1f83 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -3,7 +3,11 @@
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
**
+<<<<<<< Symbol.java
** $Id$
+=======
+** $Id$
+>>>>>>> 1.80
\* */
//todo check significance of JAVA flag.
@@ -508,6 +512,11 @@ public abstract class Symbol implements Modifiers, Kinds {
return owner().enclClass();
}
+ /** The next enclosing method */
+ public Symbol enclMethod() {
+ return isMethod() ? this : owner().enclMethod();
+ }
+
/** The top-level class enclosing `sym'
*/
Symbol enclToplevelClass() {
@@ -1008,7 +1017,7 @@ public abstract class Symbol implements Modifiers, Kinds {
*/
public Symbol overridingSymbol(Type sub) {
assert !isOverloaded() : this;
- Symbol sym1 = sub.lookupNonPrivate(name);
+ Symbol sym1 = sub.lookup(name);
if (sym1.kind == Kinds.NONE || (sym1.flags & STATIC) != 0) {
return Symbol.NONE;
} else {
@@ -1711,6 +1720,11 @@ public final class ErrorSymbol extends Symbol {
return this;
}
+ /** Return the next enclosing method */
+ public Symbol enclMethod() {
+ return this;
+ }
+
public Type loBound() {
return Type.ErrorType;
}
@@ -1759,6 +1773,11 @@ public final class NoSymbol extends Symbol {
return this;
}
+ /** Return the next enclosing method */
+ public Symbol enclMethod() {
+ return this;
+ }
+
public Symbol owner() {
throw new ApplicationError();
}
diff --git a/sources/scalac/symtab/SymbolTablePrinter.java b/sources/scalac/symtab/SymbolTablePrinter.java
index fdc40da179..3697e020bf 100644
--- a/sources/scalac/symtab/SymbolTablePrinter.java
+++ b/sources/scalac/symtab/SymbolTablePrinter.java
@@ -453,6 +453,8 @@ public class SymbolTablePrinter {
print('(');
for (int i = 0; i < vparams.length; i++) {
if (i > 0) print(",");
+ if ((vparams[i].flags & Modifiers.DEF) != 0)
+ print("def ");
printSymbolType(vparams[i], null);
}
print(')');
@@ -522,7 +524,9 @@ public class SymbolTablePrinter {
if (sym.isRoot()) return print("<root>");
return printPrefix(pre).printSymbolName(sym);
case CompoundType(Type[] parts, Scope members):
- return printTypes(parts," with ").space().printScope(members,true);
+ return printTypes(parts," with ").space()
+ .printScope(members,true)
+ .printSymbolUniqueId(type.symbol());
case MethodType(_, _):
return printType0(type, null);
case PolyType(_, _):
diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java
index f5b4f7ab4f..ed3dd1bac8 100644
--- a/sources/scalac/symtab/classfile/UnPickle.java
+++ b/sources/scalac/symtab/classfile/UnPickle.java
@@ -46,10 +46,13 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
this.moduleroot = root;
this.classroot = root.owner().lookup(root.name.toTypeName());
}
+ if (root != moduleroot && moduleroot.isModule()) {
+ moduleroot.moduleClass().setInfo(Type.NoType);
+ }
if (global.debug)
global.log(
"unpickle " + root + " " + classroot + " " + moduleroot + " " +
- moduleroot.moduleClass() + moduleroot.moduleClass().primaryConstructor());
+ moduleroot.moduleClass() + " " + moduleroot.moduleClass().primaryConstructor());
this.bytes = data;
this.bp = 0;
this.sourceName = sourceName;
@@ -69,8 +72,9 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
if (global.debug) global.log("unpickled " + root + ":" + root.rawInfo());//debug
if (!root.isInitialized())
throw new BadSignature(this, "it does not define " + root);
- if (moduleroot.isModule() && !moduleroot.moduleClass().isInitialized())
+ if (moduleroot.isModule() && moduleroot.moduleClass().type() == Type.NoType) {
moduleroot.setInfo(Type.NoType);
+ }
}
Type setOwner(Type tp, Symbol owner) {
diff --git a/sources/scalac/transformer/Erasure.java b/sources/scalac/transformer/Erasure.java
index e0bd2ac922..4b20d3042c 100644
--- a/sources/scalac/transformer/Erasure.java
+++ b/sources/scalac/transformer/Erasure.java
@@ -376,10 +376,14 @@ public class Erasure extends Transformer implements Modifiers {
return copy.If(tree, cond1, thenp1, elsep1).setType(owntype);
case Switch(Tree test, int[] tags, Tree[] bodies, Tree otherwise):
- test = transform(test, Type.unboxedType(TypeTags.INT));
- bodies = transform(bodies, owntype);
- otherwise = transform(otherwise, owntype);
- return copy.Switch(tree, test, tags, bodies, otherwise).setType(owntype);
+ Tree test1 = transform(test, Type.unboxedType(TypeTags.INT));
+ Tree[] bodies1 = transform(bodies, owntype);
+ Tree otherwise1 = transform(otherwise, owntype);
+ return copy.Switch(tree, test1, tags, bodies1, otherwise1).setType(owntype);
+
+ case Return(Tree expr):
+ Tree expr1 = transform(expr, tree.symbol().type().resultType());
+ return copy.Return(tree, expr1).setType(owntype);
case New(Template templ):
if (tree.type.symbol() == definitions.UNIT_CLASS)
@@ -588,8 +592,9 @@ public class Erasure extends Transformer implements Modifiers {
Tree transformLhs(Tree tree) {
Tree tree1;
switch (tree) {
- case Ident(_):
- tree1 = tree;
+ case Ident(Name name):
+ if (name == Names.ZERO) tree1 = gen.Ident(definitions.NULL);
+ else tree1 = tree;
break;
case Select(Tree qual, _):
Symbol sym = tree.symbol();
diff --git a/sources/scalac/transformer/LambdaLift.java b/sources/scalac/transformer/LambdaLift.java
index 9384055c77..6e14e6ff66 100644
--- a/sources/scalac/transformer/LambdaLift.java
+++ b/sources/scalac/transformer/LambdaLift.java
@@ -38,6 +38,7 @@ public class LambdaLift extends OwnerTransformer
final Definitions definitions;
final FreeVars free;
final LambdaLiftPhase descr;
+ private Unit unit;
public LambdaLift(Global global, LambdaLiftPhase descr) {
super(global);
@@ -48,6 +49,7 @@ public class LambdaLift extends OwnerTransformer
}
public void apply(Unit unit) {
+ this.unit = unit;
global.log(unit.source.toString());
free.initialize(unit);
currentOwner = global.definitions.ROOT_CLASS;
@@ -412,6 +414,12 @@ public class LambdaLift extends OwnerTransformer
//new scalac.ast.printer.TextTreePrinter().print("TUPLE: ").print(tree).print("\n ==> \n").print(tree1).println().end();//DEBUG
return tree1;
+ case Return(Tree expr):
+ if (tree.symbol() != currentOwner.enclMethod()) {
+ unit.error(tree.pos, "non-local return not yet implemented");
+ }
+ return super.transform(tree);
+
case Apply(Tree fn, Tree[] args):
Symbol fsym = TreeInfo.methSymbol(fn);
Tree fn1 = transform(fn);
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 11b715fe56..6d54de146c 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -1834,6 +1834,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
pushContext(tree, sym, context.scope);
rhs1 = transform(rhs, EXPRmode, tpe1.type);
popContext();
+ } else if ((sym.flags & (MUTABLE | DEFERRED)) == MUTABLE) {
+ rhs1 = gen.mkDefaultValue(tree.pos, sym.type());
}
sym.flags |= LOCKED;
checkNonCyclic(tree.pos, tpe1.type);
@@ -1987,6 +1989,26 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
return copy.If(tree, cond1, thenp1, elsep1)
.setType(Type.lub(new Type[]{thenp1.type, elsep1.type}));
+ case Throw(Tree expr):
+ Tree expr1 = transform(
+ expr, EXPRmode, definitions.JAVA_THROWABLE_TYPE);
+ return gen.Select(tree.pos, expr1, definitions.THROW);
+
+ case Return(Tree expr):
+ if (!context.owner.isInitialized()) {
+ return error(tree.pos, "method with return needs result type");
+ } else {
+ Symbol enclFun = context.owner.enclMethod();
+ if (enclFun.kind == VAL) {
+ Tree expr1 = transform(
+ expr, EXPRmode, enclFun.type().resultType());
+ return copy.Return(tree, expr1)
+ .setSymbol(enclFun).setType(definitions.ALL_TYPE);
+ } else {
+ return error(tree.pos, "return outside method definition");
+ }
+ }
+
case New(Tree.Template templ):
switch (templ) {
case Template(Tree[] parents, Tree[] body):
diff --git a/sources/scalac/typechecker/DeSugarize.java b/sources/scalac/typechecker/DeSugarize.java
index 472b6f0a27..f56348feea 100644
--- a/sources/scalac/typechecker/DeSugarize.java
+++ b/sources/scalac/typechecker/DeSugarize.java
@@ -176,116 +176,6 @@ public class DeSugarize implements Kinds, Modifiers {
vparam.tpe = gen.mkType(vparam.pos, pt);
}
- /** (x_1: T_1, ..., x_n: T_N) => e ==>
- * new scala.Object() with scala.Function[T_1, ..., T_N, T]() {
- * def apply(x_1: T_1, ..., x_N: T_N): T = e
- * def toString(): java.lang.String = "<function>"
- * }
- * where T = `restpe'
- * T_i = `argtpes[i]'
- * T_i's might be missing in the original tree.
- */
- public Tree Function(Tree tree, Type restype) {
- switch (tree) {
- case Function(ValDef[] vparams, Tree body):
- int length = vparams.length;
- Tree restpe = gen.mkType(tree.pos, meth2fun(restype));
-
- Tree[] argtpes = new Tree[length + 1];
- for (int i = 0; i < length; i++)
- argtpes[i] = vparams[i].tpe;
- argtpes[vparams.length] = restpe;
- Tree objConstr = make.Apply(
- tree.pos,
- make.Select(
- tree.pos,
- make.Ident(tree.pos, Names.scala),
- Names.Object.toTypeName()),
- Tree.EMPTY_ARRAY);
- Tree constr = make.Apply(
- tree.pos,
- make.TypeApply(
- tree.pos,
- make.Select(
- tree.pos,
- make.Ident(tree.pos, Names.scala),
- Name.fromString("Function" + length).toTypeName()),
- argtpes),
- Tree.EMPTY_ARRAY);
-
- Tree applyDef = make.DefDef(
- tree.pos, 0, Names.apply,
- Tree.AbsTypeDef_EMPTY_ARRAY, new ValDef[][]{vparams},
- restpe, body);
-
- Tree toStringDef = make.DefDef(
- tree.pos, Modifiers.OVERRIDE, Names.toString,
- Tree.AbsTypeDef_EMPTY_ARRAY,
- new ValDef[][]{Tree.ValDef_EMPTY_ARRAY},
- gen.mkType(tree.pos, global.definitions.JAVA_STRING_TYPE),
- make.Literal(tree.pos, "<function>"));
-
- Tree result = make.New(tree.pos,
- make.Template(tree.pos,
- new Tree[]{objConstr, constr},
- new Tree[]{applyDef, toStringDef}));
- print(tree, "mkfun", result);
- return result;
- default:
- throw new ApplicationError();
- }
- }
-
- /** Cases, Argtpe, Restpe ==>
- * new scala.PartialFunction[Argtpe, Restpe]() {
- * def apply(x: Argtpe): Restpe = x match {Cases}
- * def isDefinedAt(x: Argtpe): scala.Boolean = x match {Cases'}
- * }
- * WHERE
- * case P1 if G1 => E1, ..., Pn if Gn => En) = Cases
- * Cases' = case P1 if G1 => True, ..., Pn if Gn => True, _ => False
- * Argtpe = targs[0]
- * Restpe = targs[1]
- public Tree partialFunction(Tree tree, Type pattpe, Type restpe) {
- Tree constr =
- make.Apply(
- tree.pos,
- make.TypeApply(
- tree.pos,
- make.Select(
- tree.pos,
- make.Ident(tree.pos, Names.scala),
- Names.PartialFunction.toConstrName()),
- new Tree[]{gen.mkType(tree.pos, pattpe),
- gen.mkType(tree.pos, restpe)}),
- Tree.EMPTY_ARRAY);
- Name x = getvar();
- ValDef param = (ValDef) make.ValDef(
- tree.pos, PARAM, x, gen.mkType(tree.pos, pattpe), Tree.Empty);
- ValDef[][] vparams = new ValDef[][]{new ValDef[]{param}};
- Tree body = make.Apply(tree.pos,
- make.Select(tree.pos,
- make.Ident(tree.pos, x), Names.match), new Tree[]{tree});
- Tree applyDef = make.DefDef(
- tree.pos, 0, Names.apply, Tree.AbsTypeDef_EMPTY_ARRAY, vparams,
- gen.mkType(tree.pos, restpe), body);
- Tree tree1 = isDefinedAtVisitor(tree);
- Tree body1 = make.Apply(tree.pos,
- make.Select(tree.pos,
- make.Ident(tree.pos, x), Names.match), new Tree[]{tree1});
- Tree isDefinedAtDef = make.DefDef(
- tree.pos, 0, Names.isDefinedAt, Tree.AbsTypeDef_EMPTY_ARRAY,
- Tree.duplicator.transform(vparams),
- gen.mkType(tree.pos, global.definitions.BOOLEAN_TYPE), body1);
- Tree result = make.New(tree.pos,
- make.Template(
- tree.pos, new Tree[]{constr}, new Tree[]{applyDef, isDefinedAtDef}));
-
- print(tree, "partialfun", result);
- return result;
- }
- */
-
Tree isDefinedAtVisitor(Tree tree) {
switch (tree) {
case Visitor(CaseDef[] cases):
@@ -540,7 +430,7 @@ public class DeSugarize implements Kinds, Modifiers {
Tree getter = make.DefDef(
tree.pos, mods1, name,
Tree.AbsTypeDef_EMPTY_ARRAY, Tree.ValDef_EMPTY_ARRAY_ARRAY,
- tpe,
+ tpe.duplicate(),
((mods & DEFERRED) != 0) ? Tree.Empty
: make.Ident(tree.pos, valname));
if ((mods1 & MUTABLE) == 0) {
@@ -552,7 +442,7 @@ public class DeSugarize implements Kinds, Modifiers {
Tree.AbsTypeDef_EMPTY_ARRAY,
new ValDef[][]{{
(ValDef) make.ValDef(
- tree.pos, SYNTHETIC | PARAM, parameterName(0), tpe, Tree.Empty)}},
+ tree.pos, SYNTHETIC | PARAM, parameterName(0), tpe.duplicate(), Tree.Empty)}},
gen.mkType(tree.pos, global.definitions.UNIT_TYPE),
((mods1 & DEFERRED) != 0) ? Tree.Empty
: make.Assign(
diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java
index 10ddafedb9..76c0649ec4 100644
--- a/sources/scalac/util/Names.java
+++ b/sources/scalac/util/Names.java
@@ -24,6 +24,7 @@ public class Names {
public static final Name COMPOUND_NAME = Name.fromString("<ct>");
public static final Name ANON_CLASS_NAME = Name.fromString("$anon");
public static final Name OUTER_PREFIX = Name.fromString("outer");
+ public static final Name ZERO = Name.fromString("<zero>");
public static final Name CONSTRUCTOR = Name.fromString("<init>");
diff --git a/test/files/pos/simplelists.scala b/test/files/pos/simplelists.scala
index 143bbdd77b..73b04a8762 100644
--- a/test/files/pos/simplelists.scala
+++ b/test/files/pos/simplelists.scala
@@ -5,7 +5,7 @@
}
object Nil extends List[All] {
- def error(msg: String): All = new java.lang.Error(msg).throw;
+ def error(msg: String): All = throw new java.lang.Error(msg);
def head: All = error("Nil.head");
def tail: List[All] = error("Nil.tail");
}
diff --git a/test/pos/simplelists.scala b/test/pos/simplelists.scala
index 143bbdd77b..73b04a8762 100644
--- a/test/pos/simplelists.scala
+++ b/test/pos/simplelists.scala
@@ -5,7 +5,7 @@
}
object Nil extends List[All] {
- def error(msg: String): All = new java.lang.Error(msg).throw;
+ def error(msg: String): All = throw new java.lang.Error(msg);
def head: All = error("Nil.head");
def tail: List[All] = error("Nil.tail");
}