diff --git a/.gitignore b/.gitignore index 78ad24c7e..1d58e8916 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ tools/maprange/maprange tools/unkeyed/unkeyed *.so +*.orig diff --git a/sema/account_test.go b/sema/account_test.go index 7c7bc60fd..162ae3e88 100644 --- a/sema/account_test.go +++ b/sema/account_test.go @@ -1072,6 +1072,48 @@ func TestCheckAccountContractsAdd(t *testing.T) { `) require.NoError(t, err) }) + + t.Run("resource self as argument, with move", func(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, ` + access(all) resource R { + access(all) fun addToAccount(_ account: auth(Contracts) &Account) { + account.contracts.add( + name: "foo", + code: "012".decodeHex(), + <- self, + ) + } + } + `) + + errors := RequireCheckerErrors(t, err, 1) + + var invalidMoveError *sema.InvalidSelfInvalidationError + require.ErrorAs(t, errors[0], &invalidMoveError) + }) + + t.Run("resource self as argument, without move", func(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, ` + access(all) resource R { + access(all) fun addToAccount(_ account: auth(Contracts) &Account) { + account.contracts.add( + name: "foo", + code: "012".decodeHex(), + self, + ) + } + } + `) + + errors := RequireCheckerErrors(t, err, 1) + + var missingMoveOperationError *sema.MissingMoveOperationError + require.ErrorAs(t, errors[0], &missingMoveOperationError) + }) } func TestCheckAccountContractsUpdate(t *testing.T) { diff --git a/sema/check_invocation_expression.go b/sema/check_invocation_expression.go index 505ebf78a..a7dcf6c54 100644 --- a/sema/check_invocation_expression.go +++ b/sema/check_invocation_expression.go @@ -480,7 +480,11 @@ func (checker *Checker) checkInvocation( for i := minCount; i < argumentCount; i++ { argument := invocationExpression.Arguments[i] // TODO: pass the expected type to support type inferring for parameters - argumentTypes[i] = checker.VisitExpression(argument.Expression, invocationExpression, nil) + argumentType := checker.VisitExpression(argument.Expression, invocationExpression, nil) + + argumentTypes[i] = argumentType + + checker.checkInvocationArgumentMove(argument.Expression, argumentType) } }