-
Notifications
You must be signed in to change notification settings - Fork 267
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
For function postcondition violations, point to the problematic expression branch #5681
For function postcondition violations, point to the problematic expression branch #5681
Conversation
…mplementation assertion
…AndResultDescription
…xAndResultDescription
…xAndResultDescription
Source/DafnyCore/Resolver/NameResolutionAndTypeInference/NameResolutionAndTypeInference.cs
Show resolved
Hide resolved
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-3804c.dfy
Outdated
Show resolved
Hide resolved
@@ -1526,17 +1560,17 @@ void CheckWellformedLetExprWithResult(LetExpr e, WFOptions wfOptions, Bpl.Expr r | |||
var letBody = Substitute(e.Body, null, substMap); | |||
CheckWellformed(letBody, wfOptions, locals, builder, etran); | |||
if (e.Constraint_Bounds != null) { | |||
var substMap_prime = SetupBoundVarsAsLocals(lhsVars, builder, locals, etran); | |||
var nonGhostMap_prime = new Dictionary<IVariable, Expression>(); | |||
var substMapPrime = SetupBoundVarsAsLocals(lhsVars, builder, locals, etran); |
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.
I think it would match better C# idioms to write.
var substMapPrime = SetupBoundVarsAsLocals(lhsVars, builder, locals, etran); | |
var substMap2 = SetupBoundVarsAsLocals(lhsVars, builder, locals, etran); |
The original code looks like written by someone who missed the substMap'
notation Dafny offers 😁
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.
Really??? I don't think it improves anything. But sure I'll rename it.
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.
For me it improves maintainability. At first when I looked at "substMapPrime" I was thinking of prime numbers, which had nothing to do with that. Then I looked everywhere to see what "prime" was referring to and I did not find that. Then I realized it could be a character encoding of the ' and it made sense. Just want to avoid future confusion.
We could also replace the "2" by something more self-explaining, like substMapLocalVars
Source/DafnyCore/Verifier/BoogieGenerator.Functions.Wellformedness.cs
Outdated
Show resolved
Hide resolved
Source/DafnyCore/Verifier/BoogieGenerator.Functions.Wellformedness.cs
Outdated
Show resolved
Hide resolved
…xAndResultDescription
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.
Only two comments. Still a few check warnings in BoogieExtractor.cs line 190 as well.
Otherwise looks good.
@@ -1431,16 +1431,16 @@ void AddWellformednessCheck(RedirectingTypeDecl decl) { | |||
// parameters of the procedure | |||
var inParams = MkTyParamFormals(decl.TypeArgs, true); | |||
Type baseType; | |||
Bpl.Expr wh; | |||
Bpl.Expr whereClause; |
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.
Useful renaming.
// check that the witness expression checks out | ||
witnessExpr = Substitute(decl.Constraint, decl.Var, result); | ||
witnessExpr = decl.Constraint != null ? Substitute(decl.Constraint, decl.Var, decl.Witness) : null; |
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.
witnessExpr = decl.Constraint != null ? Substitute(decl.Constraint, decl.Var, decl.Witness) : null; | |
witnessExpr = decl.Constraint != null ? Substitute(decl.Constraint, decl.Var, decl.Witness) : decl.Witness; |
?
CheckResultToBeInType(decl.tok, witness, decl.Var.Type, locals, witnessCheckBuilder, etran, $"trying witness {witnessString}: "); | ||
witnessExpr = Substitute(decl.Constraint, decl.Var, witness); | ||
CheckResultToBeInType(decl.tok, witness, baseType, locals, witnessCheckBuilder, etran, $"trying witness {witnessString}: "); | ||
witnessExpr = decl.Constraint != null ? Substitute(decl.Constraint, decl.Var, witness) : null; |
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.
Same question as above. I'm surprised that witnessExpr can be null even if there is a witness given.
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.
I copied these changes from #5547. I'm afraid I don't understand them myself. @ssomayyajula do you?
// var delayer = new ReadsCheckDelayer(etran, null, locals, builderInitializationArea, constraintCheckBuilder); | ||
// delayer.DoWithDelayedReadsChecks(false, wfo => { | ||
// CheckWellformedAndAssume(decl.Constraint, wfo, locals, constraintCheckBuilder, etran, "predicate subtype constraint"); | ||
// }); |
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.
// var delayer = new ReadsCheckDelayer(etran, null, locals, builderInitializationArea, constraintCheckBuilder); | |
// delayer.DoWithDelayedReadsChecks(false, wfo => { | |
// CheckWellformedAndAssume(decl.Constraint, wfo, locals, constraintCheckBuilder, etran, "predicate subtype constraint"); | |
// }); |
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.
All the warnings at the bottom that are unrelated to your PR will be fixed by #5694
Great job for making this to work.
Description
If the result of an expression does not satisfy the constraints of its context, then an error is reported in the branch of the expression that does not satisfy the context.
Effected contexts:
Example of improved error reporting:
How has this been tested?
ast/functions/ensuresReporting.dfy
ast/subsetTypes/errorReporting.dfy
ast/expression/functionCall.dfy
ast/statement/localAssignment.dfy
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.