summaryrefslogtreecommitdiff
path: root/Dafny
diff options
context:
space:
mode:
authorGravatar rustanleino <unknown>2010-06-09 23:02:36 +0000
committerGravatar rustanleino <unknown>2010-06-09 23:02:36 +0000
commit9521767199e98aafb780421b859da3fb8773af42 (patch)
tree930872c273b4072ef18e00d5c05b7ce9652b539b /Dafny
parentbcd8949ab6d5bd86dc3e81226b1f936d05babfa4 (diff)
Dafny: Another bug fix in SplitExpr, having to do with generic results of function calls
Diffstat (limited to 'Dafny')
-rw-r--r--Dafny/DafnyAst.ssc13
-rw-r--r--Dafny/Translator.ssc21
2 files changed, 31 insertions, 3 deletions
diff --git a/Dafny/DafnyAst.ssc b/Dafny/DafnyAst.ssc
index 1ea2e150..a8a93067 100644
--- a/Dafny/DafnyAst.ssc
+++ b/Dafny/DafnyAst.ssc
@@ -1346,6 +1346,19 @@ namespace Microsoft.Dafny
}
}
+ public class UnboxingCastExpr : Expression { // an UnboxingCastExpr is used only as a temporary placeholding during translation
+ public readonly Expression! E;
+ public readonly Type! FromType;
+ public readonly Type! ToType;
+
+ public UnboxingCastExpr(Expression! e, Type! fromType, Type! toType) {
+ base(e.tok);
+ E = e;
+ FromType = fromType;
+ ToType = toType;
+ }
+ }
+
public class MaybeFreeExpression {
public readonly Expression! E;
public readonly bool IsFree;
diff --git a/Dafny/Translator.ssc b/Dafny/Translator.ssc
index caa8fb2b..fd757b39 100644
--- a/Dafny/Translator.ssc
+++ b/Dafny/Translator.ssc
@@ -3075,6 +3075,10 @@ namespace Microsoft.Dafny {
BoxingCastExpr e = (BoxingCastExpr)expr;
return CondApplyBox(e.tok, TrExpr(e.E), e.FromType, e.ToType);
+ } else if (expr is UnboxingCastExpr) {
+ UnboxingCastExpr e = (UnboxingCastExpr)expr;
+ return CondApplyUnbox(e.tok, TrExpr(e.E), e.FromType, e.ToType);
+
} else {
assert false; // unexpected expression
}
@@ -3551,9 +3555,18 @@ namespace Microsoft.Dafny {
}
public IEnumerable<Expression!>! SplitExpr(Expression! expr, bool expandFunctions)
- requires expr.Type is BoolType;
+ requires expr.Type is BoolType || (expr is BoxingCastExpr && ((BoxingCastExpr)expr).E.Type is BoolType);
{
- if (expr is BinaryExpr) {
+ if (expr is BoxingCastExpr) {
+ BoxingCastExpr bce = (BoxingCastExpr)expr;
+ foreach (Expression e in SplitExpr(bce.E, expandFunctions)) {
+ assert bce != null; // the necessity of this cast is a compiler bug, but perhaps an irrepairable one
+ Expression r = new BoxingCastExpr(e, bce.FromType, bce.ToType);
+ r.Type = bce.ToType; // resolve here
+ yield return r;
+ }
+
+ } else if (expr is BinaryExpr) {
BinaryExpr bin = (BinaryExpr)expr;
if (bin.ResolvedOp == BinaryExpr.ResolvedOpcode.And) {
foreach (Expression e in SplitExpr(bin.E0, expandFunctions)) {
@@ -3620,7 +3633,9 @@ namespace Microsoft.Dafny {
Expression body = Substitute(fexp.Function.Body, fexp.Receiver, substMap);
foreach (Expression se in SplitExpr(body, false)) {
assert fexp != null && fexp.Function != null; // already checked above, but the compiler seems to have forgotten that
- yield return se;
+ Expression piece = new UnboxingCastExpr(se, fexp.Function.ResultType, (!)expr.Type);
+ piece.Type = expr.Type; // resolve here
+ yield return piece;
}
assert fexp != null && fexp.Function != null; // already checked above, but the compiler seems to have forgotten that
yield break;