What TPZ5028 means
Detached mutator method
- Семейство
- topaz
- Этап
- check
- Код
TPZ5028
Причина и условия
A mutator call on a value without a root binding produces TPZ5027 when its result is discarded. Taking a mutator method as a value produces TPZ5028. A mutation through an immutable root produces TPZ5003.
| Position | Result consumption |
|---|---|
Expression statement, let _, normal tail of defer, tail of a for or while body | Discarded |
Parentheses, block, normal result of if with else, or match | Inherits the parent position |
Then tail of if without else | Discarded regardless of the parent |
Explicit return, function or lambda return tail | Used at that function boundary |
| Named binding initializer, argument, condition, operator operand, or receiver | Used |
On the same access or call, TPZ5028 takes priority over TPZ5003, which takes priority over TPZ5027. Errors in other subexpressions, the existing optional-assignment prohibition, and import-reassignment diagnostics remain visible. Whether a named binding is later read, or a caller uses a returned value, is not tracked.
Связанное правило · Mutation result consumption →Действия
Use a lambda that calls the method on its receiver.
Compiler phase: check. The primary location is the detached member access. This diagnostic takes priority over TPZ5003.
A detached mutator loses the storage path it must change.
A mutator method cannot be detached. This rejection takes priority over an immutable root error on the same access.
How to fix it
Use a lambda that calls the method on its receiver.
Examples
Rejected mutator use
let mut xs = [1]let add = xs.push
Ожидаемый результат
Ожидаемый результат
Этап отклонения check. Ненулевой код завершения.
detached-mutator-method
Контракт обязательного основного местоположения не определён.
Accepted repair
let mut xs = [1]let add = (value: int) => xs.push(value)
Ожидаемый результат
Ожидаемый результат
Проверка принимает программу. Код завершения 0.