forked from dafny-lang/dafny
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reference the correct
this
after removing the tail call of a f…
…unction or method (dafny-lang#5474) Fixes dafny-lang#4684 --------- Co-authored-by: Aaron Tomb <[email protected]>
- Loading branch information
1 parent
aa1662a
commit 91e60fb
Showing
7 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4684.dfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s" | ||
|
||
class C { | ||
var data: nat | ||
var next: C? | ||
|
||
constructor (n: nat) { | ||
data := n; | ||
if n == 0 { | ||
next := null; | ||
} else { | ||
next := new C(n - 1); | ||
} | ||
} | ||
|
||
function FWithoutTailRecursion(n: nat, g: () ~> int): int | ||
requires g.requires() | ||
reads * | ||
{ | ||
if n == 0 || next == null then | ||
g() | ||
else | ||
var h := () reads this => this.data; | ||
var r := next.FWithoutTailRecursion(n - 1, if n < 20 then g else h); | ||
r | ||
} | ||
|
||
function F(n: nat, g: () ~> int): int | ||
requires g.requires() | ||
reads * | ||
{ | ||
if n == 0 || next == null then | ||
g() | ||
else | ||
var h := () reads this => this.data; | ||
next.F(n - 1, if n < 20 then g else h) | ||
} | ||
} | ||
|
||
method Main() { | ||
var c := new C(25); | ||
print c.FWithoutTailRecursion(25, () => -1), "\n"; // 20 | ||
print c.F(25, () => -1), "\n"; // 20 | ||
} |
2 changes: 2 additions & 0 deletions
2
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4684.dfy.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
20 | ||
20 |
1 change: 1 addition & 0 deletions
1
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4684.dfy.rs.check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CHECK: error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reference the correct `this` after removing the tail call of a function or method |