diff options
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 9 | ||||
-rw-r--r-- | sources/scalac/ast/parser/PatternNormalizer.java | 12 |
2 files changed, 15 insertions, 6 deletions
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index a25b219d3b..ff36b2c4fc 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -1198,7 +1198,8 @@ public class Parser implements Tokens { s.nextToken(); choices.append( pattern1() ); } - TreeList ts = pN.flattenAlternativeChildren( choices.toArray() ); + Tree[] tarr = choices.toArray(); + TreeList ts = pN.flattenAlternativeChildren( tarr ); return pN.flattenAlternative( make.Alternative( pos, ts.toArray() ) ); } return first; @@ -1335,10 +1336,10 @@ public class Parser implements Tokens { Tree[] ts = Tree.EMPTY_ARRAY; if( s.token!= RPAREN ) ts = patterns(); - Tree t; - if (ts.length == 1) + Tree t = null; + if ((ts.length == 1)&&!( ts[0] instanceof Tree.Alternative )) { t = ts[0]; - else { + } else { t = pN.flattenSequence(make.Sequence(s.pos, ts)); t = pN.elimSequence(t); } diff --git a/sources/scalac/ast/parser/PatternNormalizer.java b/sources/scalac/ast/parser/PatternNormalizer.java index 70dc2fe789..8b69ef84ae 100644 --- a/sources/scalac/ast/parser/PatternNormalizer.java +++ b/sources/scalac/ast/parser/PatternNormalizer.java @@ -245,18 +245,26 @@ public class PatternNormalizer { // main algo for (1), precondition: choices are children of an Alternative node TreeList flattenAlternativeChildren( Tree[] choices ) { + boolean allEmpty = true; TreeList cs = new TreeList(); for( int j = 0; j < choices.length; j++ ) { Tree tree = flattenAlternative( choices[ j ] ); // flatten child switch( tree ) { case Alternative( Tree[] child_choices ): + int tmp = cs.length(); appendNonEmpty( cs, child_choices ); + if( cs.length() != tmp ) + allEmpty = false; break; default: - appendNonEmpty( cs, tree ); + cs.append( tree ); + allEmpty = allEmpty && TreeInfo.isEmptySequence( tree ); } } - //System.out.println( cs.length() ); + if( allEmpty ) { + cs.clear(); + cs.append(make.Sequence(choices[0].pos, Tree.EMPTY_ARRAY)); + } return cs; } |