diff --git a/runtime/sema/check_assignment.go b/runtime/sema/check_assignment.go index d8429a4025..6d1b838c16 100644 --- a/runtime/sema/check_assignment.go +++ b/runtime/sema/check_assignment.go @@ -125,7 +125,6 @@ func (checker *Checker) checkAssignment( } func (checker *Checker) rootOfAccessChain(target ast.Expression) (baseVariable *Variable, accessChain []Type) { - accessChain = make([]Type, 0) var inAccessChain = true // seek the variable expression (if it exists) at the base of the access chain @@ -393,23 +392,21 @@ func (checker *Checker) visitMemberExpressionAssignment( memberType = member.TypeAnnotation.Type - if !memberType.IsResourceType() { - return - } - - // if the member is a resource, check that it is not captured in a function, - // based off the activation depth of the root of the access chain, i.e. `a` in `a.b.c` - // we only want to make this check for transactions, as they are the only "resource-like" types - // (that can contain resources and must destroy them in their `execute` blocks), that are themselves - // not checked by the capturing logic, since they are not themselves resources. - baseVariable, _ := checker.rootOfAccessChain(target) + if memberType.IsResourceType() { + // if the member is a resource, check that it is not captured in a function, + // based off the activation depth of the root of the access chain, i.e. `a` in `a.b.c` + // we only want to make this check for transactions, as they are the only "resource-like" types + // (that can contain resources and must destroy them in their `execute` blocks), that are themselves + // not checked by the capturing logic, since they are not themselves resources. + baseVariable, _ := checker.rootOfAccessChain(target) - if baseVariable == nil { - return - } + if baseVariable == nil { + return + } - if _, isTransaction := baseVariable.Type.(*TransactionType); isTransaction { - checker.checkResourceVariableCapturingInFunction(baseVariable, member.Identifier) + if _, isTransaction := baseVariable.Type.(*TransactionType); isTransaction { + checker.checkResourceVariableCapturingInFunction(baseVariable, member.Identifier) + } } return diff --git a/runtime/tests/checker/access_test.go b/runtime/tests/checker/access_test.go index 1b56d7749f..aa882e986b 100644 --- a/runtime/tests/checker/access_test.go +++ b/runtime/tests/checker/access_test.go @@ -1884,6 +1884,7 @@ func TestCheckAccessImportGlobalValueVariableDeclarationWithSecondValue(t *testi `) require.NoError(t, err) + // these capture x and y because they are created in a different file _, err = ParseAndCheckWithOptions(t, ` import x, y, createR from "imported"