summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-03-05 11:01:29 +0000
committerMartin Odersky <odersky@gmail.com>2003-03-05 11:01:29 +0000
commit013290fbda547e7040a007faa0972cfa52799b45 (patch)
treeb9f3b3d22eb5bb2764e2543811aaee19632b3c57
parentbfe856410301b7aed1ab3f35c846d683ac207269 (diff)
downloadscala-013290fbda547e7040a007faa0972cfa52799b45.tar.gz
scala-013290fbda547e7040a007faa0972cfa52799b45.tar.bz2
scala-013290fbda547e7040a007faa0972cfa52799b45.zip
*** empty log message ***
-rw-r--r--sources/scalac/ast/TreeInfo.java4
-rw-r--r--sources/scalac/symtab/Type.java17
-rw-r--r--sources/scalac/transformer/LambdaLiftPhase.java5
-rw-r--r--sources/scalac/transformer/PatternMatcher.java6
-rw-r--r--sources/scalac/transformer/matching/PatternMatcher.java6
-rw-r--r--sources/scalac/typechecker/Analyzer.java22
-rw-r--r--sources/scalac/typechecker/DeSugarize.java9
-rw-r--r--test/files/pos/partialfun.scala10
-rw-r--r--test/pos/partialfun.scala10
9 files changed, 56 insertions, 33 deletions
diff --git a/sources/scalac/ast/TreeInfo.java b/sources/scalac/ast/TreeInfo.java
index e75c1c063c..a3537e3f19 100644
--- a/sources/scalac/ast/TreeInfo.java
+++ b/sources/scalac/ast/TreeInfo.java
@@ -91,9 +91,9 @@ public class TreeInfo {
case Super(_):
return true;
case Ident(_):
- return tree.type.isStable();
+ return tree.symbol().isStable();
case Select(Tree qual, _):
- return tree.type.isStable() && isPureExpr(qual);
+ return tree.symbol().isStable() && isPureExpr(qual);
case Typed(Tree expr, _):
return isPureExpr(expr);
case Literal(_):
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index df4e0d51a2..a11f8bea8f 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -582,6 +582,8 @@ public class Type implements Modifiers, Kinds, TypeTags {
Scope members1 = map(members);
if (parts1 == parts && members1 == members) {
return tp;
+ } else if (members1 == members && !tp.symbol().isCompoundSym()) {
+ return compoundType(parts1, members, tp.symbol());
} else {
Scope members2 = new Scope();
//Type tp1 = compoundType(parts1, members2);
@@ -694,17 +696,6 @@ public class Type implements Modifiers, Kinds, TypeTags {
public Symbol map(Symbol sym) { return sym; }
public Symbol[] map(Symbol[] syms) { return syms; }
public Scope map(Scope s) { return s; }
- public Type map(Type tp) {
- switch (tp) {
- case CompoundType(Type[] parts, Scope members):
- if (!tp.symbol().isCompoundSym()) {
- Type[] parts1 = map(parts);
- if (parts1 == parts) return tp;
- else return compoundType(parts1, members, tp.symbol());
- }
- }
- return super.map(tp);
- }
}
// baseType and asSeenFrom --------------------------------------------------------
@@ -1395,8 +1386,8 @@ public class Type implements Modifiers, Kinds, TypeTags {
return
sym == sym1 ||
((sym.kind == sym1.kind || sym1.kind == TYPE) &&
- self.memberInfo(sym).isSubType(
- sym1.info().substThis(sym.owner(), self))) ||
+ self.memberInfo(sym).subst(symbol().typeParams(), typeArgs())
+ .isSubType(sym1.info().substThis(sym.owner(), self))) ||
(sym.kind == TYPE && sym1.kind == ALIAS &&
sym1.info().unalias().isSameAs(sym.type()));
}
diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java
index 4208e6ede1..65c96dd231 100644
--- a/sources/scalac/transformer/LambdaLiftPhase.java
+++ b/sources/scalac/transformer/LambdaLiftPhase.java
@@ -53,7 +53,10 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
tp1 = transform(tp, sym);
break;
default:
- tp1 = transform(tp, sym.owner());
+ if (sym.kind == CLASS)
+ tp = transform(tp, sym);
+ else
+ tp1 = transform(tp, sym.owner());
}
}
if ((sym.flags & Modifiers.CAPTURED) != 0) return refType(tp1);
diff --git a/sources/scalac/transformer/PatternMatcher.java b/sources/scalac/transformer/PatternMatcher.java
index b9137daf32..44304292ed 100644
--- a/sources/scalac/transformer/PatternMatcher.java
+++ b/sources/scalac/transformer/PatternMatcher.java
@@ -99,12 +99,12 @@ public class PatternMatcher {
this.owner = owner;
this.selector = selector;
this.root = makeConstrPat(selector.pos,
- selector.type);
+ selector.type.widen());
this.root.and = makeHeader(selector.pos,
- selector.type,
+ selector.type.widen(),
make.Ident(selector.pos,
root.symbol().name)
- .setType(selector.type)
+ .setType(selector.type.widen())
.setSymbol(root.symbol()));
this.resultVar = new TermSymbol(selector.pos,
RESULT_N,
diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java
index b9137daf32..44304292ed 100644
--- a/sources/scalac/transformer/matching/PatternMatcher.java
+++ b/sources/scalac/transformer/matching/PatternMatcher.java
@@ -99,12 +99,12 @@ public class PatternMatcher {
this.owner = owner;
this.selector = selector;
this.root = makeConstrPat(selector.pos,
- selector.type);
+ selector.type.widen());
this.root.and = makeHeader(selector.pos,
- selector.type,
+ selector.type.widen(),
make.Ident(selector.pos,
root.symbol().name)
- .setType(selector.type)
+ .setType(selector.type.widen())
.setSymbol(root.symbol()));
this.resultVar = new TermSymbol(selector.pos,
RESULT_N,
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index e8e8daef27..1318cd0aac 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -1672,13 +1672,23 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
.setType(tp);
case Visitor(Tree.CaseDef[] cases):
- if (infer.isFullyDefined(pt)) {
- Type pt1 = pt.baseType(definitions.PARTIALFUNCTION_CLASS);
- if (pt1.symbol() == definitions.PARTIALFUNCTION_CLASS)
+ if (pt.symbol().isSubClass(definitions.PARTIALFUNCTION_CLASS)) {
+ Type pft = pt.baseType(definitions.PARTIALFUNCTION_CLASS);
+ Type[] pftargs = pft.typeArgs();
+ if (pft.typeArgs().length == 2 && infer.isFullyDefined(pftargs[0])) {
+ Type pattpe = pftargs[0];
+ Type restpe = pftargs[1];
+ Tree tree1 = transformVisitor(tree, pattpe, restpe);
+ if (!infer.isFullyDefined(restpe)) restpe = tree1.type;
return transform(
- desugarize.partialFunction(tree, pt1.typeArgs()));
+ desugarize.partialFunction(
+ tree, pattpe, restpe.dropVariance()));
+ } else {
+ return error(tree, "expected pattern type of cases could not be determined");
+ }
+ } else {
+ return transform(desugarize.Visitor(tree));
}
- return transform(desugarize.Visitor(tree));
case Assign(Apply(Tree funarray, Tree[] vparam), Tree rhs):
return transform(desugarize.Update(tree));
@@ -1905,7 +1915,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
}
return tree1.setType(
(pt != null && pt.isStable() || (mode & QUALmode) != 0)
- ? clazz.thisType() : clazz.type());
+ ? clazz.thisType() : clazz.typeOfThis());
case Select(Tree qual, Name name):
int qualmode = EXPRmode | POLYmode | QUALmode;
diff --git a/sources/scalac/typechecker/DeSugarize.java b/sources/scalac/typechecker/DeSugarize.java
index 228c94b286..ea74af72e4 100644
--- a/sources/scalac/typechecker/DeSugarize.java
+++ b/sources/scalac/typechecker/DeSugarize.java
@@ -237,17 +237,16 @@ public class DeSugarize implements Kinds, Modifiers {
* Argtpe = targs[0]
* Restpe = targs[1]
*/
- public Tree partialFunction(Tree tree, Type[] targs) {
- Type argtpe = targs[0];
- Type restpe = targs[1].dropVariance();
+ public Tree partialFunction(Tree tree, Type pattpe, Type restpe) {
Tree constr = make.TypeApply(tree.pos,
make.Select(tree.pos,
make.Ident(tree.pos, Names.scala),
Names.PartialFunction.toConstrName()),
- new Tree[]{gen.mkType(tree.pos, argtpe), gen.mkType(tree.pos, restpe)});
+ new Tree[]{gen.mkType(tree.pos, pattpe),
+ gen.mkType(tree.pos, restpe)});
Name x = getvar();
ValDef param = (ValDef) make.ValDef(
- tree.pos, PARAM, x, gen.mkType(tree.pos, argtpe), Tree.Empty);
+ 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,
diff --git a/test/files/pos/partialfun.scala b/test/files/pos/partialfun.scala
new file mode 100644
index 0000000000..57efb1d2ea
--- /dev/null
+++ b/test/files/pos/partialfun.scala
@@ -0,0 +1,10 @@
+module partialfun {
+
+ def applyPartial[b](f: PartialFunction[Option[String], b])(x: Option[String]) =
+ if (f.isDefinedAt(x)) f(x) else "<undefined>";
+
+ applyPartial {
+ case Some(x) => x
+ } (None());
+
+} \ No newline at end of file
diff --git a/test/pos/partialfun.scala b/test/pos/partialfun.scala
new file mode 100644
index 0000000000..57efb1d2ea
--- /dev/null
+++ b/test/pos/partialfun.scala
@@ -0,0 +1,10 @@
+module partialfun {
+
+ def applyPartial[b](f: PartialFunction[Option[String], b])(x: Option[String]) =
+ if (f.isDefinedAt(x)) f(x) else "<undefined>";
+
+ applyPartial {
+ case Some(x) => x
+ } (None());
+
+} \ No newline at end of file