Skip to content

Commit

Permalink
Caching of initializeMemberResolvers seems to cause a bug
Browse files Browse the repository at this point in the history
For contracts that contain both a .cdc source file, with Cadence code,
and with some functions being implemented natively, the GetMembers()
does not return the natively implemented members.
  • Loading branch information
m-Peter committed Sep 15, 2023
1 parent 97c3c2e commit 0f9ba5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4262,7 +4262,11 @@ func (t *CompositeType) GetMembers() map[string]MemberResolver {
}

func (t *CompositeType) initializeMemberResolvers() {
t.memberResolversOnce.Do(func() {
t.memberResolversOnce.Do(t.initializerMemberResolversFunc())
}

func (t *CompositeType) initializerMemberResolversFunc() func() {
return func() {
memberResolvers := MembersMapAsResolvers(t.Members)

// Check conformances.
Expand All @@ -4281,7 +4285,13 @@ func (t *CompositeType) initializeMemberResolvers() {
})

t.memberResolvers = withBuiltinMembers(t, memberResolvers)
})
}
}

func (t *CompositeType) ResolveMembers() {
if t.Members.Len() != len(t.GetMembers()) {
t.initializerMemberResolversFunc()()
}
}

func (t *CompositeType) FieldPosition(name string, declaration ast.CompositeLikeDeclaration) ast.Position {
Expand Down
1 change: 1 addition & 0 deletions runtime/stdlib/test_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ func newTestContractType() *TestContractType {
ty.expectFailureFunction = newTestTypeExpectFailureFunction(
expectFailureFunctionType,
)
compositeType.ResolveMembers()

return ty
}
Expand Down

0 comments on commit 0f9ba5d

Please sign in to comment.