Skip to content

Commit

Permalink
apply suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 authored and SupunS committed May 9, 2024
1 parent c94785f commit a9a7723
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
29 changes: 13 additions & 16 deletions runtime/sema/check_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/tests/checker/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a9a7723

Please sign in to comment.