Skip to content

Commit f862d08

Browse files
authored
fix: Add CanCall’s for default-valued parameters of method calls (#6091)
Fixes #6090 <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
1 parent 5cd765a commit f862d08

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

Source/DafnyCore/Verifier/Statements/BoogieGenerator.TrCall.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ void ProcessCallStmt(CallStmt cs, Dictionary<TypeParameter, Type> tySubst, Bpl.E
212212
} else {
213213
actual = Args[i];
214214
}
215-
if (!(actual is DefaultValueExpression)) {
215+
216+
if (actual is DefaultValueExpression) {
217+
builder.Add(TrAssumeCmd(actual.Origin, etran.CanCallAssumption(actual)));
218+
} else {
216219
TrStmt_CheckWellformed(actual, builder, locals, etran, true);
217220
}
218221
builder.Add(new CommentCmd("ProcessCallStmt: CheckSubrange"));
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %testDafnyForEachResolver "%s"
2+
3+
module Wrappers {
4+
datatype Option<T> = Some(value: T) | None
5+
6+
class Box<T> {
7+
var value: T
8+
9+
constructor(value: T) {
10+
this.value := value;
11+
}
12+
}
13+
}
14+
15+
module A {
16+
17+
import opened Wrappers
18+
19+
function DefaultFooArg(): Option<Box<int>>
20+
21+
method Foo(x: Option<Box<int>> := DefaultFooArg())
22+
modifies if x.Some? then {x.value} else {}
23+
{}
24+
}
25+
26+
module B refines A {
27+
function DefaultFooArg(): Option<Box<int>> {
28+
None
29+
}
30+
}
31+
32+
module C {
33+
import B
34+
35+
method Bar() {
36+
B.Foo();
37+
}
38+
}
39+
40+
// ------------------------
41+
// Smaller repro, plus tests for function calls and datatype constructors with default-value parameters
42+
43+
module D {
44+
function F(): int { 3 }
45+
46+
method Foo(u: int := F())
47+
requires u < 10
48+
{
49+
}
50+
51+
function Bar(u: int := F()): int
52+
requires u < 10
53+
{
54+
0
55+
}
56+
57+
type Small = x: int | x < 10
58+
59+
datatype Cell = Cell(s: Small := F())
60+
61+
method Test() {
62+
Foo();
63+
var bar := Bar();
64+
var cell := Cell();
65+
}
66+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Dafny program verifier finished with 6 verified, 0 errors

0 commit comments

Comments
 (0)