summaryrefslogtreecommitdiff
path: root/sources/scalac/transformer
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-06-11 12:01:19 +0000
committerMartin Odersky <odersky@gmail.com>2003-06-11 12:01:19 +0000
commitc055dc83e3ad095ec287d19d0b0c620241c70580 (patch)
tree847db3cd56e35920233bae54ca2b8d37ebc4e65f /sources/scalac/transformer
parent34cdd069a106b0889594f3c784e39b1ce1d8f3af (diff)
downloadscala-c055dc83e3ad095ec287d19d0b0c620241c70580.tar.gz
scala-c055dc83e3ad095ec287d19d0b0c620241c70580.tar.bz2
scala-c055dc83e3ad095ec287d19d0b0c620241c70580.zip
*** empty log message ***
Diffstat (limited to 'sources/scalac/transformer')
-rw-r--r--sources/scalac/transformer/LambdaLift.java1
-rw-r--r--sources/scalac/transformer/PatternMatcher.java110
-rw-r--r--sources/scalac/transformer/matching/PatternMatcher.java110
3 files changed, 113 insertions, 108 deletions
diff --git a/sources/scalac/transformer/LambdaLift.java b/sources/scalac/transformer/LambdaLift.java
index fd89c3c260..1e90f95624 100644
--- a/sources/scalac/transformer/LambdaLift.java
+++ b/sources/scalac/transformer/LambdaLift.java
@@ -197,6 +197,7 @@ public class LambdaLift extends OwnerTransformer
public Tree transform(Tree tree) {
//if (global.debug) global.debugPrinter.print("free ").print(tree).println().end();//DEBUG
+ assert tree.type != null : tree;
traverseTypeMap.apply(tree.type.widen());
Symbol sym = tree.symbol();
switch(tree) {
diff --git a/sources/scalac/transformer/PatternMatcher.java b/sources/scalac/transformer/PatternMatcher.java
index d15a6d22a1..3426a52424 100644
--- a/sources/scalac/transformer/PatternMatcher.java
+++ b/sources/scalac/transformer/PatternMatcher.java
@@ -345,7 +345,7 @@ public class PatternMatcher {
protected Tree[] patternArgs(Tree tree) {
switch (tree) {
case Apply(_, Tree[] args):
- if (args.length == 1)
+ if (args.length == 1 && (tree.type.symbol().flags & Modifiers.CASE) == 0)
switch (args[0]) {
case Sequence(Tree[] ts):
return ts;
@@ -378,60 +378,62 @@ public class PatternMatcher {
protected PatternNode patternNode(Tree tree, Header header, CaseEnv env) {
switch (tree) {
- case Apply(Tree fn, Tree[] args): // pattern with args
- if (args.length == 1)
- switch (args[0]) {
- case Sequence(Tree[] ts):
- return makeSequencePat(tree.pos, tree.type, ts.length);
- }
- return makeConstrPat(tree.pos, getConstrType(tree.type));
- case Typed(Ident(Name name), Tree tpe): // variable pattern
- PatternNode node =
- (header.type.isSubType(getConstrType(tpe.type))) ?
- makeDefaultPat(tree.pos, getConstrType(tpe.type))
- : makeConstrPat(tree.pos, getConstrType(tpe.type));
- if ((env != null) && (name != WILDCARD_N))
- switch (node) {
- case ConstrPat(Symbol casted):
- env.newBoundVar(
- tree.pos,
- ((Tree.Typed)tree).expr.symbol(),
- getConstrType(tpe.type),
- make.Ident(tree.pos, casted.name).
- setType(typeOf(casted)).
- setSymbol(casted));
- break;
- default:
- env.newBoundVar(
- tree.pos,
- ((Tree.Typed)tree).expr.symbol(),
- getConstrType(tpe.type),
- header.selector);
- }
- return node;
- case Ident(Name name): // pattern without args or variable
- if (tree.symbol().isPrimaryConstructor())
- return makeConstrPat(tree.pos, getConstrType(tree.type));
- else if (name.isVariable()) {
- if ((env != null) && (name != WILDCARD_N))
- env.newBoundVar(
- tree.pos,
- tree.symbol(),
- getConstrType(tree.type),
- header.selector);
- return makeDefaultPat(tree.pos, getConstrType(header.type));
- } else
+ case Apply(Tree fn, Tree[] args): // pattern with args
+ if (args.length == 1 && (tree.type.symbol().flags & Modifiers.CASE) == 0)
+ switch (args[0]) {
+ case Sequence(Tree[] ts):
+ return makeSequencePat(tree.pos, tree.type, ts.length);
+ }
+ return makeConstrPat(tree.pos, getConstrType(tree.type));
+ case Typed(Ident(Name name), Tree tpe): // variable pattern
+ PatternNode node =
+ (header.type.isSubType(getConstrType(tpe.type))) ?
+ makeDefaultPat(tree.pos, getConstrType(tpe.type))
+ : makeConstrPat(tree.pos, getConstrType(tpe.type));
+ if ((env != null) && (name != WILDCARD_N))
+ switch (node) {
+ case ConstrPat(Symbol casted):
+ env.newBoundVar(
+ tree.pos,
+ ((Tree.Typed)tree).expr.symbol(),
+ getConstrType(tpe.type),
+ make.Ident(tree.pos, casted.name).
+ setType(typeOf(casted)).
+ setSymbol(casted));
+ break;
+ default:
+ env.newBoundVar(
+ tree.pos,
+ ((Tree.Typed)tree).expr.symbol(),
+ getConstrType(tpe.type),
+ header.selector);
+ }
+ return node;
+ case Ident(Name name): // pattern without args or variable
+ if (tree.symbol().isPrimaryConstructor())
+ return makeConstrPat(tree.pos, getConstrType(tree.type));
+ else if (name.isVariable()) {
+ if ((env != null) && (name != WILDCARD_N))
+ env.newBoundVar(
+ tree.pos,
+ tree.symbol(),
+ getConstrType(tree.type),
+ header.selector);
+ return makeDefaultPat(tree.pos, getConstrType(header.type));
+ } else
return makeVariablePat(tree.pos, tree);
- case Select(_, Name name): // variable
- if (tree.symbol().isPrimaryConstructor())
- return makeConstrPat(tree.pos, getConstrType(tree.type));
- else
- return makeVariablePat(tree.pos, tree);
- case Literal(Object value):
- return makeConstantPat(tree.pos, getConstrType(tree.type), value);
- default:
- new scalac.ast.printer.TextTreePrinter().print(tree).flush();
- throw new ApplicationError(tree);
+ case Select(_, Name name): // variable
+ if (tree.symbol().isPrimaryConstructor())
+ return makeConstrPat(tree.pos, getConstrType(tree.type));
+ else
+ return makeVariablePat(tree.pos, tree);
+ case Literal(Object value):
+ return makeConstantPat(tree.pos, getConstrType(tree.type), value);
+ case Sequence(Tree[] ts):
+ return makeSequencePat(tree.pos, tree.type, ts.length);
+ default:
+ new scalac.ast.printer.TextTreePrinter().print(tree).flush();
+ throw new ApplicationError(tree);
}
}
diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java
index d15a6d22a1..3426a52424 100644
--- a/sources/scalac/transformer/matching/PatternMatcher.java
+++ b/sources/scalac/transformer/matching/PatternMatcher.java
@@ -345,7 +345,7 @@ public class PatternMatcher {
protected Tree[] patternArgs(Tree tree) {
switch (tree) {
case Apply(_, Tree[] args):
- if (args.length == 1)
+ if (args.length == 1 && (tree.type.symbol().flags & Modifiers.CASE) == 0)
switch (args[0]) {
case Sequence(Tree[] ts):
return ts;
@@ -378,60 +378,62 @@ public class PatternMatcher {
protected PatternNode patternNode(Tree tree, Header header, CaseEnv env) {
switch (tree) {
- case Apply(Tree fn, Tree[] args): // pattern with args
- if (args.length == 1)
- switch (args[0]) {
- case Sequence(Tree[] ts):
- return makeSequencePat(tree.pos, tree.type, ts.length);
- }
- return makeConstrPat(tree.pos, getConstrType(tree.type));
- case Typed(Ident(Name name), Tree tpe): // variable pattern
- PatternNode node =
- (header.type.isSubType(getConstrType(tpe.type))) ?
- makeDefaultPat(tree.pos, getConstrType(tpe.type))
- : makeConstrPat(tree.pos, getConstrType(tpe.type));
- if ((env != null) && (name != WILDCARD_N))
- switch (node) {
- case ConstrPat(Symbol casted):
- env.newBoundVar(
- tree.pos,
- ((Tree.Typed)tree).expr.symbol(),
- getConstrType(tpe.type),
- make.Ident(tree.pos, casted.name).
- setType(typeOf(casted)).
- setSymbol(casted));
- break;
- default:
- env.newBoundVar(
- tree.pos,
- ((Tree.Typed)tree).expr.symbol(),
- getConstrType(tpe.type),
- header.selector);
- }
- return node;
- case Ident(Name name): // pattern without args or variable
- if (tree.symbol().isPrimaryConstructor())
- return makeConstrPat(tree.pos, getConstrType(tree.type));
- else if (name.isVariable()) {
- if ((env != null) && (name != WILDCARD_N))
- env.newBoundVar(
- tree.pos,
- tree.symbol(),
- getConstrType(tree.type),
- header.selector);
- return makeDefaultPat(tree.pos, getConstrType(header.type));
- } else
+ case Apply(Tree fn, Tree[] args): // pattern with args
+ if (args.length == 1 && (tree.type.symbol().flags & Modifiers.CASE) == 0)
+ switch (args[0]) {
+ case Sequence(Tree[] ts):
+ return makeSequencePat(tree.pos, tree.type, ts.length);
+ }
+ return makeConstrPat(tree.pos, getConstrType(tree.type));
+ case Typed(Ident(Name name), Tree tpe): // variable pattern
+ PatternNode node =
+ (header.type.isSubType(getConstrType(tpe.type))) ?
+ makeDefaultPat(tree.pos, getConstrType(tpe.type))
+ : makeConstrPat(tree.pos, getConstrType(tpe.type));
+ if ((env != null) && (name != WILDCARD_N))
+ switch (node) {
+ case ConstrPat(Symbol casted):
+ env.newBoundVar(
+ tree.pos,
+ ((Tree.Typed)tree).expr.symbol(),
+ getConstrType(tpe.type),
+ make.Ident(tree.pos, casted.name).
+ setType(typeOf(casted)).
+ setSymbol(casted));
+ break;
+ default:
+ env.newBoundVar(
+ tree.pos,
+ ((Tree.Typed)tree).expr.symbol(),
+ getConstrType(tpe.type),
+ header.selector);
+ }
+ return node;
+ case Ident(Name name): // pattern without args or variable
+ if (tree.symbol().isPrimaryConstructor())
+ return makeConstrPat(tree.pos, getConstrType(tree.type));
+ else if (name.isVariable()) {
+ if ((env != null) && (name != WILDCARD_N))
+ env.newBoundVar(
+ tree.pos,
+ tree.symbol(),
+ getConstrType(tree.type),
+ header.selector);
+ return makeDefaultPat(tree.pos, getConstrType(header.type));
+ } else
return makeVariablePat(tree.pos, tree);
- case Select(_, Name name): // variable
- if (tree.symbol().isPrimaryConstructor())
- return makeConstrPat(tree.pos, getConstrType(tree.type));
- else
- return makeVariablePat(tree.pos, tree);
- case Literal(Object value):
- return makeConstantPat(tree.pos, getConstrType(tree.type), value);
- default:
- new scalac.ast.printer.TextTreePrinter().print(tree).flush();
- throw new ApplicationError(tree);
+ case Select(_, Name name): // variable
+ if (tree.symbol().isPrimaryConstructor())
+ return makeConstrPat(tree.pos, getConstrType(tree.type));
+ else
+ return makeVariablePat(tree.pos, tree);
+ case Literal(Object value):
+ return makeConstantPat(tree.pos, getConstrType(tree.type), value);
+ case Sequence(Tree[] ts):
+ return makeSequencePat(tree.pos, tree.type, ts.length);
+ default:
+ new scalac.ast.printer.TextTreePrinter().print(tree).flush();
+ throw new ApplicationError(tree);
}
}