-
Notifications
You must be signed in to change notification settings - Fork 266
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: Use correct type for map update expression #3060
Changes from 3 commits
25bb285
d7a7fed
ea90999
0eb4d5b
6020d3d
417bad3
4ecbb13
7d06596
48fcd66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15074,7 +15074,8 @@ public void ResolveExpressionX(Expression expr, ResolutionContext resolutionCont | |
ResolveExpression(e.Index, resolutionContext); | ||
ResolveExpression(e.Value, resolutionContext); | ||
AddXConstraint(expr.tok, "SeqUpdatable", e.Seq.Type, e.Index, e.Value, "update requires a sequence, map, or multiset (got {0})"); | ||
expr.Type = e.Seq.Type; | ||
var ty = PartiallyResolveTypeForMemberSelection(expr.tok, e.Seq.Type); | ||
expr.Type = ty; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not look right to me — there's no member selection here. Instead, shouldn't we just revert to the base type? ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't because at this point the type are not resolved. We first need to resolve identifier names (such as "foo"), hence the need to "partially resolve") |
||
|
||
} else if (expr is DatatypeUpdateExpr) { | ||
var e = (DatatypeUpdateExpr)expr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Microsoft.Dafny; | ||
|
||
public class NonZeroExitCodeIfErrorsOption : BooleanOption { | ||
public static readonly NonZeroExitCodeIfErrorsOption Instance = new(); | ||
public override object DefaultValue => true; | ||
public override string LongName => "nonzero-exit-code-if-errors"; | ||
public override string ShortName => null; | ||
public override string ArgumentName => "boolean"; | ||
|
||
public override string Description => @" | ||
if false then always exit with a 0 exit code, regardless of whether errors are found. | ||
If true (default) then use the appropriate exit code.".TrimStart(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit uncommon to have such a flag. Shouldn't we find another solution in the test suite itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have this option in a substantial portion of our 1400+ tests, whenever you have %dafny_0, it means you have this flag. What we could do is hide this option to users, but I don't know how to do that. @keyboardDrummer ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the description of that flag says "deprecated" in the old CLI:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for this test we should just use the old CLI. And we can then (in a separate PR) enhance LitTests.cs to accept |
||
|
||
public override string PostProcess(DafnyOptions options) { | ||
options.CountVerificationErrors = Get(options); | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %baredafny verify %args_0 "%s" > "%t" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keyboardDrummer yay ! we can use the new CLI for tests now. |
||
// RUN: %diff "%s.expect" "%t" | ||
|
||
type foo = m: map<int, int> | forall n <- m.Keys :: m[n] < 5 | ||
|
||
function addToFoo(m: foo): foo | ||
ensures false | ||
{ | ||
m[1 := 7] | ||
} | ||
|
||
type seq0 = s: seq<int> | forall n <- s :: n == 0 | ||
|
||
function ReplaceInSeq0(s: seq0): seq0 | ||
requires |s| > 0 | ||
ensures false | ||
{ | ||
s[0 := 1] | ||
} | ||
|
||
type map0 = m: map<int, int> | forall k <- m :: m[k] == 0 | ||
|
||
function ReplaceInMap0(m: map0): map0 | ||
requires 0 in m | ||
ensures false | ||
{ | ||
m[0 := 1] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
git-issue-3059.dfy(9,3): Error: value does not satisfy the subset constraints of 'foo' | ||
git-issue-3059.dfy(14,9): Error: A postcondition might not hold on this return path. | ||
git-issue-3059.dfy(16,10): Related location: This is the postcondition that might not hold. | ||
git-issue-3059.dfy(18,3): Error: value does not satisfy the subset constraints of 'seq0' | ||
git-issue-3059.dfy(27,3): Error: value does not satisfy the subset constraints of 'map0' | ||
|
||
Dafny program verifier finished with 3 verified, 4 errors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Use correct type for map update expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.