본문으로 건너뛰기
토파즈문서
6.05.21

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    다운로드 →

    진단 TPZ5028

    A mutator method was taken as a value without calling it on its receiver.

    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.

    PositionResult consumption
    Expression statement, let _ = E, normal tail of defer, tail of a for or while bodyDiscarded
    Parentheses, block, normal result of if with else, or matchInherits the parent position
    Then tail of if without elseDiscarded regardless of the parent
    Explicit return, function or lambda return tailUsed at that function boundary
    Named binding initializer, argument, condition, operator operand, or receiverUsed

    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.

    대응

    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

    example.tpzRejected mutator use플레이그라운드 열기 →
    1. let mut xs = [1]
    2. let add = xs.push
    기대 출력0이 아닌 종료 코드
    $ topaz check example.tpz
    기대 결과

    기대 결과

    거절 단계 check. 종료 코드가 0이 아닙니다.

    필수 기본 위치 계약은 미정입니다.

    Accepted repair

    example.tpzAccepted repair플레이그라운드 열기 →
    1. let mut xs = [1]
    2. let add = (value: int) => xs.push(value)
    기대 출력종료 코드 0
    $ topaz check example.tpz
    기대 결과

    기대 결과

    검사가 프로그램을 받아들입니다. 종료 코드 0.