Diagnostic and cause
LinkOr-pattern alternatives bind different names
- Family
- topaz
- Phase
- check
- Code
TPZ5710
Cause and conditions
During checking, TPZ5710 reports different name sets in alternatives of an or-pattern. The or-pattern binding rule defines the binding requirement.
Response
Use Some(_ when the arm does not need a binding. Otherwise bind the same names in every alternative or write separate arms.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 938-950 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
151141d7bb44· 1461-1461 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1440-1476
Compiler phase: check.
Compiler explanation: Every alternative of a binding or-pattern must bind the same set of names.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
- or-pattern alternatives must bind the same names —
⟨value⟩is bound in one alternative but not another Source
During checking, TPZ5710 reports different name sets in alternatives of an or-pattern. The or-pattern binding rule defines the binding requirement.
Different names in or-pattern alternatives
During checking, TPZ5710 reports different name sets in alternatives of an or-pattern. The or-pattern binding rule defines the binding requirement.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1440-1476
Response
LinkUse Some(_ when the arm does not need a binding. Otherwise bind the same names in every alternative or write separate arms.
Reproduction and verification
LinkRejected program
Linkfunction read(value: Option<int>) -> int {match (value) {case Some(item) | None() => 0}}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5710or-pattern-alternatives-bind-different-name-sets atexample.tpz:3:10
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1440-1476
Repaired program
Linkfunction read(value: Option<int>) -> int {match (value) {case Some(_) | None() => 0}}
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
17711dcdbc9b· 1440-1476