From abfe9c32f0b33274511014dd4f498702bbcf0d7e Mon Sep 17 00:00:00 2001 From: qunyanm Date: Thu, 11 Feb 2016 15:18:34 -0800 Subject: Fix issue 133. The return type for some compare operators was wrongly typed as int instead of bool. --- Source/Dafny/Translator.cs | 8 ++++---- Test/dafny4/Bug133.dfy | 18 ++++++++++++++++++ Test/dafny4/Bug133.dfy.expect | 2 ++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 Test/dafny4/Bug133.dfy create mode 100644 Test/dafny4/Bug133.dfy.expect diff --git a/Source/Dafny/Translator.cs b/Source/Dafny/Translator.cs index cfb77d84..0314344d 100644 --- a/Source/Dafny/Translator.cs +++ b/Source/Dafny/Translator.cs @@ -11222,7 +11222,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Lt; break; } else { - return TrToFunctionCall(expr.tok, "INTERNAL_lt_boogie", Bpl.Type.Int, e0, e1, liftLit); + return TrToFunctionCall(expr.tok, "INTERNAL_lt_boogie", Bpl.Type.Bool, e0, e1, liftLit); } case BinaryExpr.ResolvedOpcode.Le: @@ -11232,7 +11232,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Le; break; } else { - return TrToFunctionCall(expr.tok, "INTERNAL_le_boogie", Bpl.Type.Int, e0, e1, false); + return TrToFunctionCall(expr.tok, "INTERNAL_le_boogie", Bpl.Type.Bool, e0, e1, false); } case BinaryExpr.ResolvedOpcode.Ge: keepLits = true; @@ -11241,7 +11241,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Ge; break; } else { - return TrToFunctionCall(expr.tok, "INTERNAL_ge_boogie", Bpl.Type.Int, e0, e1, false); + return TrToFunctionCall(expr.tok, "INTERNAL_ge_boogie", Bpl.Type.Bool, e0, e1, false); } case BinaryExpr.ResolvedOpcode.Gt: if (isReal || !DafnyOptions.O.DisableNLarith) { @@ -11249,7 +11249,7 @@ namespace Microsoft.Dafny { bOpcode = BinaryOperator.Opcode.Gt; break; } else { - return TrToFunctionCall(expr.tok, "INTERNAL_gt_boogie", Bpl.Type.Int, e0, e1, liftLit); + return TrToFunctionCall(expr.tok, "INTERNAL_gt_boogie", Bpl.Type.Bool, e0, e1, liftLit); } case BinaryExpr.ResolvedOpcode.Add: if (!DafnyOptions.O.DisableNLarith) { diff --git a/Test/dafny4/Bug133.dfy b/Test/dafny4/Bug133.dfy new file mode 100644 index 00000000..f7da133e --- /dev/null +++ b/Test/dafny4/Bug133.dfy @@ -0,0 +1,18 @@ +// RUN: %dafny /noNLarith /compile:0 "%s" > "%t" +// RUN: %diff "%s.expect" "%t" + +module Math__div_def_i { + function my_div_pos(x:int, d:int) : int + requires d > 0; + decreases if x < 0 then (d - x) else x; + { + if x < 0 then + -1 + my_div_pos(x+d, d) + else if x < d then + 0 + else + 1 + my_div_pos(x-d, d) + } +} + + diff --git a/Test/dafny4/Bug133.dfy.expect b/Test/dafny4/Bug133.dfy.expect new file mode 100644 index 00000000..c0c48e2b --- /dev/null +++ b/Test/dafny4/Bug133.dfy.expect @@ -0,0 +1,2 @@ + +Dafny program verifier finished with 1 verified, 0 errors -- cgit v1.2.3