summaryrefslogtreecommitdiff
path: root/sources/scalac/typechecker
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-08-28 15:04:01 +0000
committerMartin Odersky <odersky@gmail.com>2003-08-28 15:04:01 +0000
commitcef4819a2034134b26db1f6eb85c8999421af5c1 (patch)
treeb57925ad96c33df8e69a75b917fa147e8495ad8a /sources/scalac/typechecker
parent1ba1b5f0d6f3fea116ea5858842bb539257f511b (diff)
downloadscala-cef4819a2034134b26db1f6eb85c8999421af5c1.tar.gz
scala-cef4819a2034134b26db1f6eb85c8999421af5c1.tar.bz2
scala-cef4819a2034134b26db1f6eb85c8999421af5c1.zip
*** empty log message ***
Diffstat (limited to 'sources/scalac/typechecker')
-rw-r--r--sources/scalac/typechecker/Analyzer.java22
-rw-r--r--sources/scalac/typechecker/DeSugarize.java114
2 files changed, 24 insertions, 112 deletions
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(