diff options
author | buraq <buraq@epfl.ch> | 2005-06-28 12:11:58 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2005-06-28 12:11:58 +0000 |
commit | c09c5c4c7553c34ac7f66d5e89cfade008d20cc0 (patch) | |
tree | c70451a73a2fa49b94e78a8efde2fc034fa3106a /sources | |
parent | fbe14f733047f017bc49f20bcd122e2f3a871065 (diff) | |
download | scala-c09c5c4c7553c34ac7f66d5e89cfade008d20cc0.tar.gz scala-c09c5c4c7553c34ac7f66d5e89cfade008d20cc0.tar.bz2 scala-c09c5c4c7553c34ac7f66d5e89cfade008d20cc0.zip |
throw match error fixed
Diffstat (limited to 'sources')
5 files changed, 20 insertions, 10 deletions
diff --git a/sources/scala/tools/nsc/matching/AlgebraicMatchers.scala b/sources/scala/tools/nsc/matching/AlgebraicMatchers.scala index 1d32485fcc..d1a3808039 100644 --- a/sources/scala/tools/nsc/matching/AlgebraicMatchers.scala +++ b/sources/scala/tools/nsc/matching/AlgebraicMatchers.scala @@ -67,7 +67,7 @@ trait AlgebraicMatchers : TransMatcher { ), If( super.toTree(root.and), Ident(resultVar ), - ThrowMatchError( _m.pos )) + ThrowMatchError( _m.pos, resultVar.tpe )) ); } diff --git a/sources/scala/tools/nsc/matching/Autom2.scala b/sources/scala/tools/nsc/matching/Autom2.scala index 0d67f0c419..a280dabe1f 100644 --- a/sources/scala/tools/nsc/matching/Autom2.scala +++ b/sources/scala/tools/nsc/matching/Autom2.scala @@ -153,7 +153,7 @@ trait Autom2: TransMatcher { /** some error happened which is due to bug in translation/automaton */ final def code_error(): Tree = { - ThrowMatchError( pos /*, funRetType() */); + ThrowMatchError( pos , funRetType() ); } def code_fail(): Tree = { diff --git a/sources/scala/tools/nsc/matching/CodeFactory.scala b/sources/scala/tools/nsc/matching/CodeFactory.scala index 7995465200..a28d76178c 100644 --- a/sources/scala/tools/nsc/matching/CodeFactory.scala +++ b/sources/scala/tools/nsc/matching/CodeFactory.scala @@ -198,9 +198,12 @@ abstract class CodeFactory: TransMatcher { Apply(Select(left, eqsym), List(right)); } - def ThrowMatchError(pos: Int ) = + def ThrowMatchError(pos: Int, tpe: Type ) = Apply( - gen.mkRef(definitions.MatchError_fail), + TypeApply( + gen.mkRef(definitions.MatchError_fail), + List(TypeTree(tpe)) + ), List( Literal(cunit.toString()), Literal(Position.line(pos)) @@ -218,8 +221,10 @@ abstract class CodeFactory: TransMatcher { ) ); */ - def Error(pos: Int) = - ThrowMatchError(pos); + +// def Error(pos: Int) = +// ThrowMatchError(pos); + /* def newPair(left: Tree, right: Tree) = diff --git a/sources/scala/tools/nsc/matching/PatternMatchers.scala b/sources/scala/tools/nsc/matching/PatternMatchers.scala index b45829378e..33e28627d4 100644 --- a/sources/scala/tools/nsc/matching/PatternMatchers.scala +++ b/sources/scala/tools/nsc/matching/PatternMatchers.scala @@ -171,12 +171,16 @@ trait PatternMatchers: (TransMatcher with PatternNodes) with PatternNodeCreator tree match { case Bind(name, Typed(Ident( nme.WILDCARD ), tpe)) => // x@_:Type if (isSubType(header.getTpe(),tpe.tpe)) { + //Console.println("U"); val node = pDefaultPat(tree.pos, tpe.tpe); env.newBoundVar( tree.symbol, tree.tpe, header.selector ); node; } else { + //Console.println("X"); val node = pConstrPat(tree.pos, tpe.tpe); - env.newBoundVar( tree.symbol, tree.tpe, typed(Ident( node.casted ))); + env.newBoundVar( tree.symbol, + tpe.tpe /*scalac: tree.tpe */, + typed(Ident( node.casted ))); node; } @@ -231,6 +235,7 @@ trait PatternMatchers: (TransMatcher with PatternNodes) with PatternNodeCreator pConstrPat(tree.pos, tree.tpe); } case t @ Typed(ident, tpe) => // variable pattern + //Console.println("Z"); val doTest = isSubType(header.getTpe(),tpe.tpe); val node = { if(doTest) @@ -629,7 +634,7 @@ trait PatternMatchers: (TransMatcher with PatternNodes) with PatternNodeCreator //print(); val ncases = numCases(root.and); - val matchError = ThrowMatchError(selector.pos); + val matchError = ThrowMatchError(selector.pos, resultVar.tpe); // without a case, we return a match error if there is no default case if (ncases == 0) return defaultBody(root.and, matchError); @@ -702,7 +707,7 @@ trait PatternMatchers: (TransMatcher with PatternNodes) with PatternNodeCreator ValDef(resultVar, EmptyTree /* DefaultValue */)); val res = If(toTree(root.and), Ident(resultVar), - ThrowMatchError(selector.pos /* , + ThrowMatchError(selector.pos, resultVar.tpe /* , Ident(root.symbol) */)); return Block(ts, res); } diff --git a/sources/scala/tools/nsc/matching/SequenceMatchers.scala b/sources/scala/tools/nsc/matching/SequenceMatchers.scala index dcbd9bc1a5..d2d8aa7414 100644 --- a/sources/scala/tools/nsc/matching/SequenceMatchers.scala +++ b/sources/scala/tools/nsc/matching/SequenceMatchers.scala @@ -116,7 +116,7 @@ trait SequenceMatchers: TransMatcher { this._m = _m; //assert body.length == pat.length; if( defaultCase == null ) - defaultCase = ThrowMatchError( _m.pos ); + defaultCase = ThrowMatchError( _m.pos, resultType ); val seqType = pat( 0 ).tpe; val elementType1 = getElemType_Sequence( seqType ); |