diff --git a/runtime/sema/check_assignment.go b/runtime/sema/check_assignment.go index b1b7898ec..e8a3dd03e 100644 --- a/runtime/sema/check_assignment.go +++ b/runtime/sema/check_assignment.go @@ -491,8 +491,6 @@ func (checker *Checker) visitMemberExpressionAssignment( reportAssignmentToConstant() } - memberType = member.TypeAnnotation.Type - 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` diff --git a/runtime/tests/checker/access_test.go b/runtime/tests/checker/access_test.go index 2c604a9df..e91c640d3 100644 --- a/runtime/tests/checker/access_test.go +++ b/runtime/tests/checker/access_test.go @@ -1850,7 +1850,9 @@ func TestCheckAccessImportGlobalValueVariableDeclarationWithSecondValue(t *testi }, ) - errs := RequireCheckerErrors(t, err, 7) + errs := RequireCheckerErrors(t, err, 9) + + // For `x` require.IsType(t, &sema.InvalidAccessError{}, errs[0]) assert.Equal(t, @@ -1870,15 +1872,19 @@ func TestCheckAccessImportGlobalValueVariableDeclarationWithSecondValue(t *testi require.IsType(t, &sema.ResourceCapturingError{}, errs[4]) + // For `y` + require.IsType(t, &sema.ResourceCapturingError{}, errs[5]) - require.IsType(t, &sema.AssignmentToConstantError{}, errs[6]) + require.IsType(t, &sema.ResourceCapturingError{}, errs[6]) + + require.IsType(t, &sema.AssignmentToConstantError{}, errs[7]) assert.Equal(t, "y", - errs[6].(*sema.AssignmentToConstantError).Name, + errs[7].(*sema.AssignmentToConstantError).Name, ) - require.IsType(t, &sema.ResourceCapturingError{}, errs[6]) + require.IsType(t, &sema.ResourceCapturingError{}, errs[8]) } func TestCheckContractNestedDeclarationPrivateAccess(t *testing.T) { diff --git a/runtime/tests/checker/resources_test.go b/runtime/tests/checker/resources_test.go index 9be6bac22..db21d40bc 100644 --- a/runtime/tests/checker/resources_test.go +++ b/runtime/tests/checker/resources_test.go @@ -10113,9 +10113,6 @@ func TestCheckInvalidNestedResourceCapture(t *testing.T) { destroy y } } - destroy() { - destroy self.x - } } `) errs := RequireCheckerErrors(t, err, 1)