Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only guard this when eliminating tail calls, if possible #5524

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Only guard this when eliminating tail calls, if possible
  • Loading branch information
fabiomadge committed Jun 4, 2024
commit 384b26bc47381689fe99fee3ee09dc2d64dfbef0
2 changes: 1 addition & 1 deletion Source/DafnyCore/Backends/SinglePassCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5733,7 +5733,7 @@ private class ArrayLvalueImpl : ILvalue {
var e = (LambdaExpr)expr;

IVariable receiver = null;
if (enclosingMethod is { IsTailRecursive: true } || enclosingFunction is { IsTailRecursive: true }) {
if (thisContext != null && (enclosingMethod is { IsTailRecursive: true } || enclosingFunction is { IsTailRecursive: true })) {
var name = ProtectedFreshId("_this");
var ty = ModuleResolver.GetThisType(e.tok, thisContext);
receiver = new LocalVariable(RangeToken.NoToken, name, ty, false) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %testDafnyForEachCompiler --refresh-exit-code=0 "%s"

function Loop(xs: seq<()>): ()
{
if |xs| == 0
then ()
else
var _: bool -> bool := e => e;
Loop(xs[1..])
}

method Main(){
print Loop([(), ()]), "\n";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECK: error\[E0277\]: the trait bound
1 change: 1 addition & 0 deletions docs/dev/news/5524.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only guard `this` when eliminating tail calls, if possible
Loading