Skip to content

Commit

Permalink
fix: typos in Compiler-java.GenericArrayElementLvalue (dafny-lang#1341)
Browse files Browse the repository at this point in the history
This specialization of ILvalue represents an lvalue of the form `a[i]` where a is an array of unknown (that is, parameterized) type. The implementation was missing a call to `EndStmt(wr)` and had an unnecessary call to `intValue()`, and the test suite somehow managed to miss exercising this case.
  • Loading branch information
robin-aws authored Aug 6, 2021
1 parent 31234f8 commit 116da25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Source/Dafny/Compiler-java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,14 +1465,15 @@ public void EmitRead(ConcreteSyntaxTree wr) {
public ConcreteSyntaxTree EmitWrite(ConcreteSyntaxTree wr) {
ConcreteSyntaxTree w;
if (Indices.Count == 1) {
wr.Write($"{FormatTypeDescriptorVariable(ElmtTypeParameter)}.setArrayElement({Array}, {Indices[0]}.intValue(),");
wr.Write($"{FormatTypeDescriptorVariable(ElmtTypeParameter)}.setArrayElement({Array}, {Indices[0]},");
w = wr.Fork();
wr.Write(")");
} else {
wr.Write($"{Array}.set({Util.Comma("", Indices, ix => $"[{DafnyHelpersClass}.toInt({ix})]")}), ");
w = wr.Fork();
wr.Write(")");
}
Compiler.EndStmt(wr);
return w;
}
}
Expand Down
7 changes: 7 additions & 0 deletions Test/comp/Arrays.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ class Cell<T> {
{
x, y := arr, arr;
}
method UArray(x: T)
modifies arr
{
if arr.Length > 0 {
arr[0] := x;
}
}
}

type ychar = ch | '\0' <= ch <= 'z'
Expand Down
2 changes: 1 addition & 1 deletion Test/comp/Arrays.dfy.expect
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Dafny program verifier finished with 41 verified, 0 errors
Dafny program verifier finished with 42 verified, 0 errors

Dafny program verifier did not attempt verification
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Expand Down

0 comments on commit 116da25

Please sign in to comment.