Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Диагностика TPZ5712

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

    Diagnostic and cause

    Ссылка

    Constructor name used as a pattern binding

    Семейство
    topaz
    Этап
    check
    Код
    TPZ5712

    Причина и условия

    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.

    Действия

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

    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.

    Правилоdiagnostics.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.

    Причина

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

    Response

    Ссылка

    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

    Ссылка

    Rejected program

    Ссылка
    example.tpzRejected programОткрыть песочницу →
    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. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • 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.

    Repaired program

    Ссылка
    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. }
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Проверка принимает программу. Код завершения 0.

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

    Меню

    Загрузка →