Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions sema/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion sema/check_invocation_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading