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

    TPZ5712 Constructor name used as a pattern binding

    A pattern binding that collides with a constructor produces TPZ5712 during checking.

    Diagnostic and cause

    Link

    Constructor name used as a pattern binding

    Family
    topaz
    Phase
    check
    Code
    TPZ5712

    Cause and conditions

    Write Name(patterns) in every pattern position. The payload list has the declared arity. A zero-payload constructor uses Name(), including None() and user enum variants such as Empty(). Nesting does not change this syntax. Parenthesized patterns with the wrong payload count retain the existing constructor-arity diagnostic.

    Write Name(arguments) in every value position at every arity. Constructor calls use None(), Empty(), or Some(value). Qualified enum construction uses the same argument list, as in Choice.Empty(). The grammar rejects a bare prelude None value. User enum constructor names are resolved and checked after parsing.

    A bare identifier in a pattern attempts to bind a new name. Its capitalization never selects a constructor role. A typed binding uses the same name rule.

    The constructor namespace includes prelude constructors, visible declarations and imports, and variants obtained from the known expected type after resolving aliases. A pattern binder that has the same identifier as one of those constructors is rejected with TPZ5712. This check applies at every nested pattern, to typed binders, and to constructors of another visible type. A value binding does not hide a constructor for this check. Choose a fresh name to capture the value or use _ to ignore it.

    None is already a reserved binding name. Without the constructor argument list it is rejected during parsing with TPZ2012. Other bare constructor names reach the namespace check. A removed bare enum pattern is never widened into a catch-all.

    Response

    Write the constructor argument list, including () at zero arity. To capture the matched value, choose a name absent from the constructor namespace.

    Source evidence

    Topaz 6.0.0 specifies this diagnostic during checking.

    The target message is pattern binding Empty conflicts with a constructor.

    The pinned SELF source does not emit this diagnostic.

    Every constructor pattern uses an argument list. A bare identifier proposes a binding and cannot collide with a visible constructor. Typed bindings use the same rule. Value shadowing does not hide constructors. Report TPZ5712 at the binding name. Bare None retains its existing parse rejection. The constructor rule defines the constructor namespace and repair.

    Rulediagnostics.tpz5712.p5.rule

    Constructor name used as a pattern binding

    Every constructor pattern uses an argument list. A bare identifier proposes a binding and cannot collide with a visible constructor. Typed bindings use the same rule. Value shadowing does not hide constructors. Report TPZ5712 at the binding name. Bare None retains its existing parse rejection. The constructor rule defines the constructor namespace and repair.

    Why

    This applies the adopted constructor-parentheses.1 decision. The language chapter owns the rejection condition and source span.

    Source evidence

    Response

    Link

    Write the constructor argument list, including () at zero arity. To capture the matched value, choose a name absent from the constructor namespace.

    Reproduction and verification

    Link

    Rejected program

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

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5712 pattern-constructor-binding-collision at example.tpz:4:14

    The matcher describes a Topaz 6.0 target message. Public Topaz 5.21.3 does not implement this diagnostic producer.

    Source evidence

    Repaired program

    Link
    example.tpzRepaired program
    1. enum Choice { Empty, Filled(int), Pair(int, int) }
    2. function read(value: Choice) -> int {
    3. match (value) {
    4. case Empty() => 0
    5. case Filled(number) => number
    6. case Pair(left, right) => left + right
    7. }
    8. }
    9. function nested(value: Option<Choice>) -> int {
    10. match (value) {
    11. case None() => -1
    12. case Some(Empty()) => 0
    13. case Some(Filled(number)) => number
    14. case Some(Pair(left, right)) => left + right
    15. }
    16. }
    Expected outputexit 0
    $ topaz check example.tpz · target product 5.21.3
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    The matcher describes a Topaz 6.0 target message. Public Topaz 5.21.3 does not implement this diagnostic producer.

    Source evidence

    Menu

    Download