Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Diagnostics

    TPZ5711: Or-pattern binding types disagree

    A name bound by multiple alternatives of an or-pattern has inconsistent types.

    Diagnostic and cause

    Link

    Or-pattern binding types disagree

    Family
    topaz
    Phase
    check
    Code
    TPZ5711

    Cause and conditions

    Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.

    Response

    Use compatible payload types for a shared binding, or split the alternatives into separate arms. The repaired enum supplies int from both alternatives.

    Source evidence

    Compiler phase: check.

    Compiler explanation: A name bound by multiple alternatives of an or-pattern has inconsistent types.

    Message templates. The marker ⟨value⟩ stands for text computed for the reported program.

    • binding ⟨value⟩ has type ⟨value⟩ in one or-pattern alternative and ⟨value⟩ in another Source

    Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.

    Rulediagnostics.tpz5711.p5.rule

    Or-pattern binding types must be compatible

    Binding the same name to disjoint payload types across or-pattern alternatives is rejected with TPZ5711. In this program, int and string cannot give value a compatible binding type.

    Source evidence

    Response

    Link

    Use compatible payload types for a shared binding, or split the alternatives into separate arms. The repaired enum supplies int from both alternatives.

    Reproduction and verification

    Link

    Rejected program

    Link
    example.tpzRejected programOpen in Playground
    1. enum Item { Count(int), Text(string) }
    2. function read(item: Item) -> int {
    3. match (item) {
    4. case Count(value) | Text(value) => 0
    5. }
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5711 diagnostic-tpz5711 at example.tpz:4:10

    The checker tests whether the collected types are disconnected under type overlap. This example establishes the disjoint int/string case; it does not require all alternative type spellings to be identical.

    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. enum Item { Count(int), Text(int) }
    2. function read(item: Item) -> int {
    3. match (item) {
    4. case Count(value) | Text(value) => 0
    5. }
    6. }
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    The checker tests whether the collected types are disconnected under type overlap. This example establishes the disjoint int/string case; it does not require all alternative type spellings to be identical.

    Source evidence

    Menu

    Download