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

Dafny suggests making a type parameter invariant instead of contravariant #2659

Closed
cpitclaudel opened this issue Aug 30, 2022 · 1 comment · Fixed by #2774
Closed

Dafny suggests making a type parameter invariant instead of contravariant #2659

cpitclaudel opened this issue Aug 30, 2022 · 1 comment · Fixed by #2774
Labels
area: error-reporting Clarity of the error reporting kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny

Comments

@cpitclaudel
Copy link
Member

Input:

datatype T<A, B> = T(A --> B)

Output:

invariant.dfy(1,21): Error: formal type parameter 'A' is not used according to its variance specification (it is used left of an arrow) (perhaps try declaring 'A' as '!A')

This should suggest -A, not !A

@cpitclaudel cpitclaudel added kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny area: error-reporting Clarity of the error reporting labels Aug 30, 2022
@RustanLeino
Copy link
Collaborator

Sometimes !A may be correct, so the hint should probably suggest both as possible fixes.

RustanLeino added a commit that referenced this issue Sep 20, 2022
…2774)

* Fixes hint to suggest both `-` and `!` instead of just `!` when a type
parameter is used in a negative position
* Improves an error message by removing the words "strict positivity",
which are confusing and not necessary (see also
http://leino.science/papers/krml280.html)

Fixes #2659

<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: error-reporting Clarity of the error reporting kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants