Skip to content

Commit

Permalink
fix: Resolution of static functions-by-method (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomadge authored Apr 16, 2022
1 parent 0b07e94 commit 462d7cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- fix: Fix induction hypothesis generated for lemmas with a receiver parameter (https://github.com/dafny-lang/dafny/pull/2002)
- fix: Make verifier understand `(!new)` (https://github.com/dafny-lang/dafny/pull/1935)
- fix: Fix initialization of non-auto-init in-parameters in C#/JavaScript/Go compilers (https://github.com/dafny-lang/dafny/pull/1935)
- fix: Resolution of static functions-by-method (https://github.com/dafny-lang/dafny/pull/2023)
- fix: Export sets did not work with inner modules (https://github.com/dafny-lang/dafny/pull/2025)


Expand Down
5 changes: 2 additions & 3 deletions Source/Dafny/Resolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,7 @@ void RegisterMembers(ModuleDefinition moduleDef, TopLevelDeclWithMembers cl,
extraMember.InheritVisibility(m, false);
members.Add(extraName, extraMember);
} else if (m is Function f && f.ByMethodBody != null) {
RegisterByMethod(f);
RegisterByMethod(f, cl);
}
} else if (m is Constructor && !((Constructor)m).HasName) {
reporter.Error(MessageSource.Resolver, m, "More than one anonymous constructor");
Expand All @@ -2317,10 +2317,9 @@ void RegisterMembers(ModuleDefinition moduleDef, TopLevelDeclWithMembers cl,
}
}

void RegisterByMethod(Function f) {
void RegisterByMethod(Function f, TopLevelDeclWithMembers cl) {
Contract.Requires(f != null && f.ByMethodBody != null);

var cl = (TopLevelDeclWithMembers)f.EnclosingClass;
var tok = f.ByMethodTok;
var resultVar = f.Result ?? new Formal(tok, "#result", f.ResultType, false, false, null);
var r = Expression.CreateIdentExpr(resultVar);
Expand Down
12 changes: 12 additions & 0 deletions Test/git-issues/git-issue-2016.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %dafny /compile:0 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

module M {
datatype D = D() {
static function f(): (res: int) {
5
} by method {
return 5;
}
}
}
2 changes: 2 additions & 0 deletions Test/git-issues/git-issue-2016.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Dafny program verifier finished with 1 verified, 0 errors

0 comments on commit 462d7cd

Please sign in to comment.