Acton
Linting rules

E035: create-message-body-to-cell

Warns about `MyMessage { ... }.toCell()` inside `createMessage({ body: ... })` initializer.

Metadata

  • Code: E035
  • Rule: create-message-body-to-cell
  • Status: Stable since v0.0.1
  • Quick fix: not available

What it does

Warns about MyMessage { ... }.toCell() inside createMessage({ body: ... }) initializer.

Why is this bad?

createMessage already accepts a serializable object as body and decides whether to inline it or wrap it into a reference cell automatically. Calling .toCell() manually is usually unnecessary and can be worse for performance because it forces an extra cell creation even when the compiler could inline a small body directly.

Example

struct Transfer {
    amount: int32
}

fun send(dest: address) {
    val msg = createMessage({
        bounce: false,
        value: ton("0.1"),
        dest,
        body: Transfer { amount: 1 }.toCell(),
E035: explicit `.toCell()` on `createMessage` body is usually unnecessary and can hurt performance
}); }

Use instead:

struct Transfer {
    amount: int32
}

fun send(dest: address) {
    val msg = createMessage({
        bounce: false,
        value: ton("0.1"),
        dest,
        body: Transfer { amount: 1 },
    });
}
Source code

Last updated on

On this page