Skip to content

Commit

Permalink
fix: Missing substitution in the subset check of the function overrid…
Browse files Browse the repository at this point in the history
…e check (#4060)

Fixes #4056.
  • Loading branch information
fabiomadge authored Jun 12, 2023
1 parent 4e43cef commit 0c31206
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Source/DafnyCore/Verifier/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3682,8 +3682,10 @@ private void AddFunctionOverrideSubsetChk(Function func, BoogieStmtListBuilder b
Dictionary<TypeParameter, Type> typeMap) {
//getting framePrime
List<FrameExpression> traitFrameExps = new List<FrameExpression>();
FunctionCallSubstituter sub = null;
foreach (var e in func.OverriddenFunction.Reads) {
var newE = Substitute(e.E, null, substMap, typeMap);
sub ??= new FunctionCallSubstituter(substMap, typeMap, (TraitDecl)func.OverriddenFunction.EnclosingClass, (ClassLikeDecl)func.EnclosingClass);
var newE = sub.Substitute(e.E);
FrameExpression fe = new FrameExpression(e.tok, newE, e.FieldName);
traitFrameExps.Add(fe);
}
Expand Down
17 changes: 17 additions & 0 deletions Test/git-issues/git-issue-4056.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %baredafny verify %args %s > %t
// RUN: %diff "%s.expect" "%t"

trait ADT {
ghost function ReprFamily(n: nat): set<object>
decreases n
ensures n > 0 ==> ReprFamily(n) >= ReprFamily(n-1)
reads this, if n == 0 then {} else ReprFamily(n-1)
}

class P extends ADT {
ghost function ReprFamily(n: nat): set<object>
decreases n
ensures n > 0 ==> ReprFamily(n) >= ReprFamily(n-1)
reads this, if n == 0 then {} else ReprFamily(n-1)
{ {} }
}
2 changes: 2 additions & 0 deletions Test/git-issues/git-issue-4056.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Dafny program verifier finished with 3 verified, 0 errors
1 change: 1 addition & 0 deletions docs/dev/news/4056.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Regression in the subset check of the function override check

0 comments on commit 0c31206

Please sign in to comment.