Skip to content

Commit b709cad

Browse files
authored
fix: Make sure Go labels are used (#1096)
1 parent 3c91407 commit b709cad

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Source/Dafny/Compiler-go.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ protected void EmitReturnWithCoercions(List<Formal> outParams, List<Formal>/*?*/
17731773

17741774
protected override TargetWriter CreateLabeledCode(string label, TargetWriter wr) {
17751775
var w = wr.ForkSection();
1776+
wr.WriteLine("goto L{0};", label);
17761777
wr.IndentLess();
17771778
wr.WriteLine("L{0}:", label);
17781779
return w;

Test/git-issues/git-issue-1093.dfy

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %dafny /compile:0 "%s" > "%t"
2+
// RUN: %dafny /noVerify /compile:4 /compileTarget:cs "%s" >> "%t"
3+
// RUN: %dafny /noVerify /compile:4 /compileTarget:js "%s" >> "%t"
4+
// RUN: %dafny /noVerify /compile:4 /compileTarget:go "%s" >> "%t"
5+
// RUN: %dafny /noVerify /compile:4 /compileTarget:java "%s" >> "%t"
6+
// RUN: %diff "%s.expect" "%t"
7+
8+
method Main() {
9+
UnusedLabel();
10+
var c := new C;
11+
c.x := 4;
12+
c.LabelUsedInGhostCode(); // 10
13+
print c.x, "\n";
14+
}
15+
16+
method UnusedLabel()
17+
{
18+
// The following once resulted in malformed Go code, in particular generating an unused labeled.
19+
label foo: {}
20+
}
21+
22+
class C {
23+
var x: int
24+
25+
method LabelUsedInGhostCode()
26+
modifies this
27+
{
28+
x := x + 2;
29+
label A:
30+
x := x + 1;
31+
label B:
32+
x := x + 3;
33+
assert x == old(x) + 6;
34+
assert x == old@A(x) + 4;
35+
assert old@B(x) + x == 2 * old(x) + 9;
36+
}
37+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
Dafny program verifier finished with 2 verified, 0 errors
3+
4+
Dafny program verifier did not attempt verification
5+
10
6+
7+
Dafny program verifier did not attempt verification
8+
10
9+
10+
Dafny program verifier did not attempt verification
11+
10
12+
13+
Dafny program verifier did not attempt verification
14+
10

0 commit comments

Comments
 (0)