-
Notifications
You must be signed in to change notification settings - Fork 256
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
Type of - inferred to be nat #1263
Comments
But, if you don't do that then the subsequent statement |
Here's another example, using the more innocently known operator type EvenUpTo100 = x | x % 2 == 0 && x <= 100
method P(N: EvenUpTo100) {
var i := N;
while i != 100
invariant i + 1 == i + 1 // error reported: result of operation may not be an 'EvenUpTo100'
{
i := i + 2;
}
} It seems we'd like to specify the type of the numeric
where |
@DavePearce If |
Hey @RustanLeino, So basically you're doing a form of type inference where constraints are checked by the verifier? That sounds similar to Whiley then! |
Technically, the desired types are inferred by a more standard type-inference engine. Then, whenever there are conditions to be validated, they are part of what gets passed to the verifier. So, in Dafny and unlike Whiley (I think), the output of the verifier does not affect what types are inferred. |
Previously, these types were inferred more lazily, which wasn't helpful for type inference elsewhere. In particular, some expressions like `n - 10` then ended up typed as `nat` instead of `int`, which in turn causes unwanted errors. This addresses issue dafny-lang#1263 in some cases.
This PR contains several improvements to type inference, and in particular it fixes the soundness issue reported in #1676. Main type fixes: * Fix soundness issue, where the verifier had left out a subset-type check * Improve type inference: For bound variables (like those in let expressions and the bound variables in case patterns), eagerly set the type of the bound variable to the type of the RHS. After all, this is the most general type one can be sure the variable can have. (This improves the situation reported in Type of - inferred to be nat #1263, but is not a full solution for that problem.) Other improvements: * fix: The desugaring of `match` into `VarDeclPattern` had incorrectly set the `isGhost` bit. (I don't think the previous error caused any problems, except for producing confusing output with `/rprint`.) * fix: Add missing space in error message * Remove an unnecessary set of `{ }` in the desugaring of `match` cases * Rename `CheckEnds` to `DetermineRootLeaf`, and add various comments * chore: Use the `out var` and `out _` syntax when calling `DetermineRootLeaf` * chore: Use the `.Count` getter instead of the `.Count()` method for `List`s Fixes #1676
The type of an integer-subtraction expression should never be inferred to be a subset type, but should be the base type thereof. This is not done properly, which causes the verifier to give an error in the following program:
While it is true that the result of
i - 1
above may not be anat
, this property should not have been checked in the first place.Workaround: change
i - 1
toi as int - 1
The text was updated successfully, but these errors were encountered: