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: Invalid Python code for nested set and map comprehensions #5287

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Source/DafnyCore/Backends/SinglePassCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5571,6 +5571,7 @@ void EmitExpr(Expression e2, ConcreteSyntaxTree wr2, bool inLetExpr, ConcreteSyn
var collectionName = ProtectedFreshId("_coll");
var setType = e.Type.NormalizeToAncestorType().AsSetType;
var bwr = CreateIIFE0(setType, e.tok, wr, wStmts);
wStmts = bwr.Fork();
wr = bwr;
EmitSetBuilder_New(wr, e, collectionName);
var n = e.BoundVars.Count;
Expand Down Expand Up @@ -5617,6 +5618,7 @@ void EmitExpr(Expression e2, ConcreteSyntaxTree wr2, bool inLetExpr, ConcreteSyn
var rantypeName = TypeName(mapType.Range, wr, e.tok);
var collection_name = ProtectedFreshId("_coll");
var bwr = CreateIIFE0(mapType, e.tok, wr, wStmts);
wStmts = bwr.Fork();
wr = bwr;
EmitMapBuilder_New(wr, e, collection_name);
var n = e.BoundVars.Count;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %testDafnyForEachCompiler "%s"

const someSet :=
set
someString <- {"D"},
someChar <-
set c <- someString :: c
:: someChar

const someMap :=
map x |
0 < x < 3
&& x in
map y : int | 0 <= y <= x :: y
:: x * x

method Main() {
print someSet, "\n";
print someMap, "\n";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{'D'}
map[1 := 1, 2 := 4]
1 change: 1 addition & 0 deletions docs/dev/news/5287.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid Python code for nested set and map comprehensions