-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fill in type arguments in implicit function-by-method postcondit…
…ion (#5068) This PR fills in any type arguments `X` to the `result = F<X>(args)` postcondition that's generated for the method part of a `function-by-method` declaration. Fixes #4998 Reviewer notes: The desugaring of `function-by-method` is done in two places in the code. I filled in the type arguments in both places. However, in the second place (which is for `{:test}` functions/methods), `dafny` would crash if any type parameters were declared (even for type parameters that were not auto-init `(0)`). Since the `{:test}` was already not allowed for functions/methods with parameters, I also added error messages if `{:test}` is used with a function/method with type parameters. <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
- Loading branch information
1 parent
fc70ede
commit 728433a
Showing
13 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
...IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3839/git-issue-3839a.dfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
// RUN: ! %baredafny test --use-basename-for-filename --show-snippets:false "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
method {:test} M(x: int) returns (r: int) | ||
method {:test} M(x: int) returns (r: int) // error: in-parameters not supported | ||
{ | ||
expect x != x; | ||
return x; | ||
expect x != x; | ||
return x; | ||
} | ||
|
||
method {:test} MethodWithTypeParameters<X(0)>() returns (y: X) { // error: type parameters not supported | ||
y := *; | ||
} | ||
|
||
method {:test} MethodWithTypeParameter<X>() returns (u: seq<X>) { // error: type parameters not supported | ||
u := []; | ||
} | ||
|
||
predicate {:test} UnusedTypeParameterForFunctionByMethod<A>() { // error: type parameters not supported | ||
true | ||
} by method { | ||
return true; | ||
} |
5 changes: 4 additions & 1 deletion
5
...tionTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3839/git-issue-3839a.dfy.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
git-issue-3839a.dfy(4,15): Error: Methods with the :test attribute may not have input arguments | ||
1 resolution/type errors detected in git-issue-3839a.dfy | ||
git-issue-3839a.dfy(10,15): Error: Methods with the :test attribute may not have type parameters | ||
git-issue-3839a.dfy(14,15): Error: Methods with the :test attribute may not have type parameters | ||
git-issue-3839a.dfy(18,18): Error: Methods with the :test attribute may not have type parameters | ||
4 resolution/type errors detected in git-issue-3839a.dfy |
8 changes: 8 additions & 0 deletions
8
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4998.dfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: %testDafnyForEachResolver "%s" | ||
|
||
// this once crashed, because the implicit postcondition didn't include the type parameter | ||
predicate Foo<A>() { | ||
true | ||
} by method { | ||
return true; | ||
} |
2 changes: 2 additions & 0 deletions
2
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4998.dfy.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Dafny program verifier finished with 1 verified, 0 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Don't emit an error message for a `function-by-method` with unused type parameters. |