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

fix: Crash related to the override check for generic functions #3692

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Source/DafnyCore/Verifier/FunctionCallSubstituter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ public override Expression Substitute(Expression expr) {
if (expr is FunctionCallExpr e) {
var receiver = Substitute(e.Receiver);
var newArgs = SubstituteExprList(e.Args);
var typeApplicationAtEnclosingClass = e.TypeApplication_AtEnclosingClass;
Function function;
if ((e.Function.EnclosingClass == Tr || Tr.InheritedMembers.Contains(e.Function)) && e.Receiver is ThisExpr && receiver is ThisExpr && Cl.Members.Find(m => m.OverriddenMember == e.Function) is { } f) {
receiver = new ThisExpr((TopLevelDeclWithMembers)f.EnclosingClass);
function = (Function)f;
typeApplicationAtEnclosingClass = receiver.Type.AsParentType(Cl).TypeArgs.ToList();
} else {
function = e.Function;
}
return new FunctionCallExpr(e.tok, e.Name, receiver, e.OpenParen, e.CloseParen, newArgs, e.AtLabel) {
Function = function,
Type = e.Type, // TODO: this may not work with type parameters.
TypeApplication_AtEnclosingClass = SubstituteTypeList(e.TypeApplication_AtEnclosingClass), // resolve here
TypeApplication_AtEnclosingClass = SubstituteTypeList(typeApplicationAtEnclosingClass), // resolve here
TypeApplication_JustFunction = SubstituteTypeList(e.TypeApplication_JustFunction), // resolve here
IsByMethodCall = e.IsByMethodCall
};
Expand Down
12 changes: 12 additions & 0 deletions Test/git-issues/git-issue-3691.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %exits-with 0 %dafny /compile:0 /allocated:4 /functionSyntax:4 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

trait A {
predicate f()
method g() ensures f()
}

class B<T> extends A {
predicate f() { true }
method g() ensures f()
}
2 changes: 2 additions & 0 deletions Test/git-issues/git-issue-3691.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Dafny program verifier finished with 2 verified, 0 errors
1 change: 1 addition & 0 deletions docs/dev/news/3692.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crash related to the override check for generic functions