Skip to content
Topazdocs

Search documentation

Specification 6.0

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

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

    Download →

    Design decisions

    Expressions, patterns and control flow

    Positive values use no unary plus

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    A leading + could be written before a positive number or another operand. Removing it left the value unchanged.

    Decision

    Remove unary +. Write the operand directly.

    Examples

    Rejecting unary plus before an integer

    example.tpzRejecting unary plus before an integerOpen in Playground →
    1. let value = +1
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    Rejecting unary plus before a bound value

    example.tpzRejecting unary plus before a bound valueOpen in Playground →
    1. let value = 1
    2. let copy = +value
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    Rejecting unary plus before a float

    example.tpzRejecting unary plus before a floatOpen in Playground →
    1. let value = +1.5
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    Using ordinary values, negation, and binary addition

    example.tpzUsing ordinary values, negation, and binary additionOpen in Playground →
    1. import std.io
    2. let value = 3
    3. io.writeLine("{1}")
    4. io.writeLine("{1.5}")
    5. io.writeLine("{value}")
    6. io.writeLine("{-value}")
    7. io.writeLine("{value + 2}")
    Expected outputExit code 0
    1
    1.5
    3
    -3
    5
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 1
    2. 1.5
    3. 3
    4. -3
    5. 5

    Alternatives considered

    • Keep unary +. It would give the same value a second spelling.

    Why

    A unary operator signals an operation on the value.

    Changed rules Unary operators →

    In tests membership in arrays, sets and ranges

    Adopted November 7, 2026 · 6.0.0 · In progress

    Problem

    An operator and a method could both answer whether a collection contains an element. A substring search or a map lookup asks a different question.

    Decision

    • Use in to test membership in arrays, sets and ranges. Set.contains is removed.
    • Substring tests and map key lookups retain their own operations.

    Examples

    Use in for arrays, sets, and ranges

    example.tpzUse in for arrays, sets, and rangesOpen in Playground →
    1. import std.io
    2. let values = [1, 3]
    3. let members = set { 1, 3 }
    4. let odds = 1..<5 by 2
    5. io.writeLine("{1 in values}:{2 in values}")
    6. io.writeLine("{1 in members}:{2 in members}")
    7. io.writeLine("{1 in odds}:{2 in odds}")
    Expected outputExit code 0
    true:false
    true:false
    true:false
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. true:false
    2. true:false
    3. true:false

    A Map is not an element-membership container

    example.tpzA Map is not an element-membership containerOpen in Playground →
    1. let found = "key" in map { "key": 1 }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    The required primary-location contract is Pending.

    Substring search is not element membership

    example.tpzSubstring search is not element membershipOpen in Playground →
    1. let found = "a" in "abc"
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    The required primary-location contract is Pending.

    Alternatives considered

    • Keep both contains and in. One membership test would have two spellings.

    Why

    The operation shows whether code is testing an element, a substring or a key.

    Changed rules Comparison and membership →

    An absent optional receiver skips method arguments

    Adopted November 18, 2026 · 6.0.0 · Being verified

    Problem

    An argument can print or fail even when there is no receiver. If it ran on that path, skipping the call would have an unexpected effect.

    Decision

    • Evaluate the receiver once. For None() or null, skip lookup, arguments, spreads, callback construction and omitted defaults. Return the same absence.
    • For a present value, find the method on the unwrapped value and use ordinary call order.
    • Check the signature and arguments statically even when the receiver is absent.
    • An Option result is not wrapped twice. A nullable receiver keeps null distinct.
    • Only read methods of a built-in type can be taken as values. Taking a mutating method as a value is rejected.

    Examples

    Option receiver, present

    example.tpzOption receiver, present
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: Option<P> = Some(P { x: 1 })
    7. let result: Option<int> = p?.plus(2)
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Option receiver, absent

    example.tpzOption receiver, absent
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: Option<P> = None()
    7. let result: Option<int> = p?.plus(2)
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Option result stays one layer

    example.tpzOption result stays one layer
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: Option<P> = Some(P { x: 1 })
    7. let result: Option<int> = p?.next()
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Nullable receiver, present

    example.tpzNullable receiver, present
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: P | null = P { x: 1 }
    7. let result: int | null = p?.plus(2)
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Nullable receiver, absent

    example.tpzNullable receiver, absent
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: P | null = null
    7. let result: int | null = p?.plus(2)
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Nullable receiver with Option return

    example.tpzNullable receiver with Option return
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: P | null = P { x: 1 }
    7. let result: Option<int> | null = p?.next()
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Absent receiver still checks member

    example.tpzAbsent receiver still checks memberOpen in Playground →
    1. record P { x: int }
    2. impl P {
    3. function plus(self, n: int) -> int { self.x + n }
    4. function next(self) -> Option<int> { Some(self.x + 1) }
    5. }
    6. let p: Option<P> = None()
    7. let result = p?.missing(1)
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    The required primary-location contract is Pending.

    Absent receiver skips argument expression

    example.tpzAbsent receiver skips argument expression
    1. import std.io
    2. record P { x: int }
    3. impl P { function plus(self, n: int) -> int { self.x + n } }
    4. function argument() -> int {
    5. io.writeLine("arg")
    6. 2
    7. }
    8. let p: Option<P> = None()
    9. let result = p?.plus(argument())
    10. io.writeLine("done")
    Expected outputExit code 0
    done
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. done

    Optional union checks every arm

    example.tpzOptional union checks every arm
    1. record A { x: int }
    2. record B { x: int }
    3. impl A { function plus(self, n: int) -> int { self.x + n } }
    4. impl B { function plus(self, n: string) -> int { self.x } }
    5. let value: (A | B) | null = null
    6. let result = value?.plus(2)
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    The required primary-location contract is Pending.

    Alternatives considered

    • Keep blocking ?. only for user methods, as now. Built-in and user methods would follow different call rules, and the same intent would need a longer if let or match.
    • Block ?. for built-in methods too. The specification already treats optional access with the general member rule.

    Why

    The receiver determines whether arguments run, for both built-in and user methods.

    Changed rules Member, index, and optional access →

    Ordinary calls and bindings express data flow

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    A value could be passed to a function with either call syntax or a pipeline. Reusing an intermediate result or ordering effects also needed a clear spelling.

    Decision

    • Remove |>, >> and expression-position _. Compose work with ordinary calls and functions.
    • Use let to show evaluation order and reuse intermediate values.

    Examples

    Reject a pipeline placeholder

    example.tpzReject a pipeline placeholderOpen in Playground →
    1. function subtract(a: int, b: int) -> int { a - b }
    2. let value = 3 |> subtract(10, _)
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    The required primary-location contract is Pending.

    Reject the composition operator

    example.tpzReject the composition operatorOpen in Playground →
    1. function increment(n: int) -> int { n + 1 }
    2. function double(n: int) -> int { n * 2 }
    3. let composed = increment >> double
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    The required primary-location contract is Pending.

    Reject a standalone expression placeholder

    example.tpzReject a standalone expression placeholderOpen in Playground →
    1. let value = _
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    The required primary-location contract is Pending.

    Save values to preserve call and composition effects

    example.tpzSave values to preserve call and composition effectsOpen in Playground →
    1. import std.io
    2. function input() -> int {
    3. io.writeLine("input")
    4. 3
    5. }
    6. function subtract(a: int, b: int) -> int { a - b }
    7. function stage() -> (int, int) -> int {
    8. io.writeLine("callee")
    9. subtract
    10. }
    11. function argument() -> int {
    12. io.writeLine("argument")
    13. 10
    14. }
    15. let saved = input()
    16. let callee = stage()
    17. let written = argument()
    18. io.writeLine("{callee(written, saved)}")
    19. function increment(n: int) -> int { n + 1 }
    20. function double(n: int) -> int { n * 2 }
    21. function first() -> (int) -> int {
    22. io.writeLine("first")
    23. increment
    24. }
    25. function second() -> (int) -> int {
    26. io.writeLine("second")
    27. double
    28. }
    29. let left = first()
    30. let right = second()
    31. let composed = (n: int) => right(left(n))
    32. io.writeLine("{composed(3)}:{composed(5)}")
    Expected outputExit code 0
    input
    callee
    argument
    7
    first
    second
    8:12
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. input
    2. callee
    3. argument
    4. 7
    5. first
    6. second
    7. 8:12

    Alternatives considered

    • Keep some pipeline and composition operators. Ordinary calls and operator syntax would still express the same calls in different forms.
    • Keep all the operators. One call should have one way to write it.

    Why

    Calls and bindings show where a value goes and when it is evaluated.

    Changed rules Ordinary calls and saved values →Compose calls in a function body →

    Parentheses delimit control operands

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    A record or lambda in a control header can make its boundary unclear. A separate grammar for headers also complicates moving an ordinary expression into one.

    Decision

    • Wrap control operands and guards in parentheses, as in if (test), match (value) and while (test).
    • Write range patterns as (low .. high). Inside the parentheses, use ordinary expression syntax.

    Examples

    Reject an undelimited if operand

    example.tpzReject an undelimited if operandOpen in Playground →
    1. let value = if true { 1 } else { 0 }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:16

    Record construction and update use ordinary operand grammar

    example.tpzRecord construction and update use ordinary operand grammarOpen in Playground →
    1. import std.io
    2. record Flag { enabled: bool }
    3. let state = { enabled: true }
    4. let first = if (Flag { enabled: true }.enabled) { 1 } else { 0 }
    5. let second = if (state { enabled: false }.enabled) { 1 } else { 2 }
    6. let third = match (Flag { enabled: true }) {
    7. case Flag { enabled: true } => true
    8. case _ => false
    9. }
    10. io.writeLine("{first},{second},{third}")
    Expected outputExit code 0
    1,2,true
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 1,2,true

    Reject an unwrapped range pattern

    example.tpzReject an unwrapped range patternOpen in Playground →
    1. let value = match (2) {
    2. case 1 .. 3 => 1
    3. case _ => 0
    4. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      range-pattern-parentheses at example.tpz:2:10

    A delimited range precedes a lambda-valued arm

    example.tpzA delimited range precedes a lambda-valued armOpen in Playground →
    1. import std.io
    2. let low = 1
    3. let high = 3
    4. let chosen = match (2) {
    5. case (low .. high) => (value: int) => value + 1
    6. case _ => (value: int) => value
    7. }
    8. io.writeLine("{chosen(6)}")
    Expected outputExit code 0
    7
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 7

    Alternatives considered

    • Keep a dedicated grammar for control headers. Expressions would follow different rules when moved into a header.
    • Change the record and lambda shorthand grammar instead. Expression grammar would still differ by context.

    Why

    The boundary is visible, and the same expression syntax works throughout the program.

    Changed rules Explicit control operands →Range pattern boundaries →

    Operands evaluate from left to right

    Adopted November 9, 2026 · 6.0.0 · Being verified

    Problem

    If both operands can print or fail, the first evaluation can change the observable result. A defined order tells developers which fault appears.

    Decision

    • Evaluate binary operands and nested operands from left to right. Report the first runtime fault.
    • Short-circuit operators evaluate only the operands they need. Call arguments and collection and record elements follow source order.

    Examples

    Binary and nested operands print from left to right

    example.tpzBinary and nested operands print from left to rightOpen in Playground →
    1. import std.io
    2. function value(label: string, number: int) -> int {
    3. io.writeLine(label)
    4. number
    5. }
    6. let result = value("left", 1) + value("middle", 2) * value("right", 3)
    7. io.writeLine("{result}")
    Expected outputExit code 0
    left
    middle
    right
    7
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. left
    2. middle
    3. right
    4. 7

    The left operand faults before the right operand runs

    example.tpzThe left operand faults before the right operand runsOpen in Playground →
    1. import std.io
    2. function left(divisor: int) -> int {
    3. io.writeLine("left")
    4. 1 / divisor
    5. }
    6. function right(number: int) -> int {
    7. io.writeLine("right")
    8. 9223372036854775807 + number
    9. }
    10. left(0) + right(1)
    Expected outputNonzero exit
    left
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    Expected stdout
    1. left

    Alternatives considered

    • Leave evaluation order unspecified. The same program could print a different order or report a different first fault.

    Why

    Output and failure order follow directly from the source.

    Changed rules Operand and assignment evaluation order →

    Resolved pending items Pending: remaining evaluation-order guarantees →

    A write targets the binding after the right-hand value is evaluated

    Adopted November 16, 2026 · 6.0.0 · Being verified

    Problem

    The right-hand side of an indexed assignment or an argument to a mutating method can rebind the receiver. The result depends on which value receives the write.

    Decision

    • Indexed assignment and mutating methods write to the binding’s current value after evaluating the right-hand side or arguments.
    • The slot is checked again just before the write. If shrink rebinds xs to [7] and returns 5, xs[0] = shrink() leaves [5].

    Examples

    A write uses the receiver after the arguments rebind it

    main.tpzA write uses the receiver after the arguments rebind itOpen in Playground →
    1. import std.io
    2. let mut xs = [1, 2]
    3. function shrink() -> int {
    4. xs = [7]
    5. 5
    6. }
    7. xs[0] = shrink()
    8. io.writeLine("{xs}")
    9. let mut ys = [3]
    10. function reset() -> int {
    11. ys = [0]
    12. 4
    13. }
    14. ys.push(reset())
    15. io.writeLine("{ys}")
    Expected outputExit code 0
    [5]
    [0, 4]
    
    $ topaz run main.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. [5]
    2. [0, 4]

    Alternatives considered

    • Write to the value seen at the start of evaluation. The binding already points to a new value, so the write affects a discarded value.

    Why

    The last step of the expression has a predictable target even when evaluation rebinds the receiver.

    Changed rules Operand and assignment evaluation order →

    Numeric patterns accept negative literals

    Adopted November 18, 2026 · 6.0.0 · Being verified

    Problem

    Writing positive cases directly and negative cases as ranges or guards makes the same test look different. Signed zero also needs a consistent comparison rule.

    Decision

    • A numeric literal pattern can have one leading -. A name such as -x and a standalone grouped pattern are unavailable.
    • The pattern has the value and diagnostics of the same spelling in an expression. Numeric equality treats -0.0 and 0.0 as equal.
    • A negative-zero arm fully covered by an earlier unguarded zero arm produces TPZ5713 during checking.

    Examples

    Negative numeric literal patterns preserve expression values

    example.tpzNegative numeric literal patterns preserve expression values
    1. import std.io
    2. function integer(value: int) -> int {
    3. match (value) {
    4. case -1 => 1
    5. case -0x8000000000000000 => 2
    6. case -1_000 => 3
    7. case -0 => 4
    8. case _ => 0
    9. }
    10. }
    11. function floating(value: float) -> int {
    12. match (value) {
    13. case -1.5 => 5
    14. case -0.0 => 6
    15. case _ => 0
    16. }
    17. }
    18. io.writeLine("{integer(-1)}")
    19. io.writeLine("{integer(-9223372036854775808)}")
    20. io.writeLine("{integer(-1000)}")
    21. io.writeLine("{integer(0)}")
    22. io.writeLine("{floating(-1.5)}")
    23. io.writeLine("{floating(0.0)}")
    Expected outputExit code 0
    1
    2
    3
    4
    5
    6
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6

    An earlier float zero case covers negative float zero

    example.tpzAn earlier float zero case covers negative float zero
    1. function classify(value: float) -> int {
    2. match (value) {
    3. case 0.0 => 1
    4. case -0.0 => 2
    5. case _ => 0
    6. }
    7. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    An earlier zero case covers negative zero

    example.tpzAn earlier zero case covers negative zero
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case 0 => 1
    4. case -0 => 2
    5. case _ => 0
    6. }
    7. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    A standalone grouped negative literal pattern is rejected

    example.tpzA standalone grouped negative literal pattern is rejectedOpen in Playground →
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case (-1) => 1
    4. case _ => 0
    5. }
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    The required primary-location contract is Pending.

    A repeated minus does not form a literal pattern

    example.tpzA repeated minus does not form a literal patternOpen in Playground →
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case --1 => 1
    4. case _ => 0
    5. }
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    The required primary-location contract is Pending.

    Alternatives considered

    • Make developers use ranges or guards for negatives. Testing one numeric value would use different spellings for positive and negative numbers.
    • Compare the two zeros by their bits. Pattern matching would disagree with ==.

    Why

    The same literal and equality rules apply regardless of sign.

    Changed rules Pattern forms and name interpretation →

    Record patterns name both the field and its pattern

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    Destructuring can give a value the same name as its field. A bare name does not show which part names the field and which part binds the value.

    Decision

    Write every record pattern field as field: pattern.

    Examples

    Rejecting a structural field shorthand

    example.tpzRejecting a structural field shorthandOpen in Playground →
    1. let { value } = { value: 1 }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      record-pattern-field-colon at example.tpz:1:13

    Rejecting a nominal field shorthand

    example.tpzRejecting a nominal field shorthandOpen in Playground →
    1. record Point { x: int }
    2. let Point { x } = Point { x: 1 }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      record-pattern-field-colon at example.tpz:2:15

    Binding and renaming fields explicitly

    example.tpzBinding and renaming fields explicitlyOpen in Playground →
    1. import std.io
    2. record Point { x: int, y: int }
    3. let { value: value } = { value: 7 }
    4. let Point { x: first, y: second } = Point { x: 2, y: 3 }
    5. io.writeLine("{value} {first} {second}")
    Expected outputExit code 0
    7 2 3
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 7 2 3

    Alternatives considered

    • Keep field shorthand with special restrictions. The same binding would have two forms and shorthand would need its own rules.

    Why

    Readers can see the field being matched and the pattern that handles its value.

    Changed rules Pattern forms and name interpretation →

    A missing colon in a record pattern is a parse error

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    A missing separator between a field and its pattern is already rejected by the parser. A separate checker diagnostic would need a new reachable condition.

    Decision

    Keep TPZ5611 reserved for defensive checks. A missing colon produces TPZ2001 during parsing.

    Examples

    Rejecting a structural field shorthand →

    Rejecting a nominal field shorthand →

    Alternatives considered

    • Define a new user-facing TPZ5611 checker condition. The same invalid spelling already fails during parsing.

    Why

    The field's syntax error is reported while reading the source.

    Changed rules Pattern forms and name interpretation →

    A match arm uses a block to return from its function

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    An arm has a result expression, yet it sometimes needs to return from the enclosing function. A bare return would blur the boundary between expressions and statements.

    Decision

    Put return inside a block when using it in a match arm.

    Examples

    Rejecting a return without an arm block

    example.tpzRejecting a return without an arm blockOpen in Playground →
    1. function choose(flag: bool) -> int {
    2. while (true) {
    3. let value = match (flag) {
    4. case true => return 7
    5. case false => 3
    6. }
    7. return value
    8. }
    9. 0
    10. }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      match-arm-return-needs-block at example.tpz:4:26

    Returning through a match arm block

    example.tpzReturning through a match arm blockOpen in Playground →
    1. import std.io
    2. function choose(flag: bool) -> int {
    3. while (true) {
    4. let value = match (flag) {
    5. case true => { return 7 }
    6. case false => 3
    7. }
    8. return value
    9. }
    10. 0
    11. }
    12. io.writeLine("{choose(true)}")
    13. io.writeLine("{choose(false)}")
    Expected outputExit code 0
    7
    3
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 7
    2. 3

    Alternatives considered

    • Allow a bare return as a special arm expression. A return statement would have a special form in match arms.
    • Allow return as an expression everywhere. One rule should hold that return is a statement.

    Why

    Returns in arm blocks follow the same statement rules as other returns.

    Changed rules Case selection and guards →

    Match picks the first successful arm and rejects covered arms

    Adopted November 8, 2026 · 6.0.0 · In progress · Version 2

    Problem

    A special case often comes before a general rule. Rejecting every overlap forces that intent into a guard or a different structure.

    Decision

    • Try match arms in source order and select the first arm whose pattern and guard both succeed.
    • A later general pattern can overlap an earlier special one.
    • Reject an arm during checking if earlier unguarded arms cover every value it could match.

    Examples

    A repeated unguarded literal case is unreachable

    example.tpzA repeated unguarded literal case is unreachable
    1. function choose(value: int) -> int {
    2. match (value) {
    3. case 1 => 10
    4. case 1 => 20
    5. case _ => 0
    6. }
    7. }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    Overlapping guarded cases follow source order

    example.tpzOverlapping guarded cases follow source orderOpen in Playground →
    1. import std.io
    2. function choose(value: int) -> string {
    3. match (value) {
    4. case number if (number > 0) => "positive"
    5. case number if (number <= 0) => "nonpositive"
    6. case _ => "other"
    7. }
    8. }
    9. io.writeLine(choose(4))
    10. io.writeLine(choose(0))
    Expected outputExit code 0
    positive
    nonpositive
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. positive
    2. nonpositive

    A later wildcard is covered by two earlier unguarded cases

    example.tpzA later wildcard is covered by two earlier unguarded cases
    1. let value: bool = true
    2. let result = match (value) {
    3. case true => "yes"
    4. case false => "no"
    5. case _ => "hidden"
    6. }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    Cover all payloads of a constructor with two bool fields

    example.tpzCover all payloads of a constructor with two bool fields
    1. enum E { Pair(bool, bool), Empty }
    2. function f(e: E) -> int { match (e) { case Pair(_, true) => 1
    3. case Pair(_, false) => 2
    4. case Empty() => 3 } }
    Expected outputExit code 0
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Alternatives considered

    • Reject overlap independently of arm order. Developers could no longer show that an exception should be handled first by writing it first.

    Why

    Special cases can come first, while checking exposes arms that can never run.

    Changed rules Case selection and guards →Reachable overlapping cases →

    Version history
    • Version 1 · Adopted November 7, 2026 · The first decision required explicit patterns to be disjoint

      Initially adopted symmetric overlap checks and one fallback branch.

    A range pattern with two literal endpoints that matches no value fails checking

    Adopted November 18, 2026 · 6.0.0 · Being verified

    Problem

    Confusing .. with ..< can produce a range that matches nothing. An enclosing arm may still be reachable, so the mistake is easy to miss.

    Decision

    • Apply the usual integer literal checks first when both endpoints are literals.
    • Checking reports TPZ5714 for (a ..< b) when a >= b or (a .. b) when a > b. Grouped literals and nested patterns follow the same rule.
    • A range with computed endpoints simply fails to match if it is empty at runtime.

    Examples

    An exclusive literal range with equal endpoints is rejected

    example.tpzAn exclusive literal range with equal endpoints is rejected
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case (0 ..< 0) => 1
    4. case _ => 0
    5. }
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    A reversed inclusive literal range is rejected

    example.tpzA reversed inclusive literal range is rejected
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case (5 .. 1) => 1
    4. case _ => 0
    5. }
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    An empty range is rejected inside a reachable alternative

    example.tpzAn empty range is rejected inside a reachable alternative
    1. function classify(value: int) -> int {
    2. match (value) {
    3. case (0 ..< 0) | 1 => 1
    4. case _ => 0
    5. }
    6. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    A for pattern rejects a static empty range

    example.tpzA for pattern rejects a static empty range
    1. for (0 ..< 0) in ([0]) {
    2. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    A computed empty range fails to match at runtime

    example.tpzA computed empty range fails to match at runtimeOpen in Playground →
    1. import std.io
    2. function endpoint(value: int) -> int { value }
    3. let result = match (0) {
    4. case (endpoint(0) ..< endpoint(0)) => 1
    5. case _ => 2
    6. }
    7. io.writeLine("{result}")
    Expected outputExit code 0
    2
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 2

    Alternatives considered

    • Reuse TPZ5713, the diagnostic for an arm already covered. An empty pattern could wrongly be blamed on an earlier arm.
    • Treat an empty literal range as an ordinary non-match. A mistaken boundary could silently leave dead code.

    Why

    The diagnostic identifies the actual range even inside an otherwise reachable arm.

    Changed rules Integer range patterns →

    Computed endpoints run each time matching reaches a range

    Adopted November 17, 2026 · 6.0.0 · Being verified

    Problem

    A later alternative can contain a failing call even when an earlier one already matches. Evaluating endpoints in advance can stop a program in work that should be skipped.

    Decision

    • On reaching a range, evaluate the computed lower endpoint before the upper one. Recompute them on each attempt.
    • Test outer patterns first and alternatives from left to right. Stop at the first matching alternative and try the next arm if the guard fails.
    • Use this order in match, for and destructuring. Faults and ? from a reached endpoint follow their ordinary control flow.

    Examples

    A successful range alternative skips later endpoints

    example.tpzA successful range alternative skips later endpoints
    1. import std.io
    2. function bound(value: int) -> int { value }
    3. function boom(divisor: int) -> int { 1 / divisor }
    4. let chosen = match (0) {
    5. case (0 .. bound(1)) | (0 .. boom(0)) => 7
    6. case _ => 9
    7. }
    8. io.writeLine("{chosen}")
    Expected outputExit code 0
    7
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 7

    A false guard continues with the next case

    example.tpzA false guard continues with the next case
    1. import std.io
    2. function end(label: string) -> int {
    3. io.writeLine(label)
    4. 1
    5. }
    6. let chosen = match (0) {
    7. case (0 .. 1) | (0 .. end("or")) if (false) => 1
    8. case (0 .. end("next")) => 2
    9. case _ => 9
    10. }
    11. io.writeLine("{chosen}")
    Expected outputExit code 0
    next
    2
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. next
    2. 2

    A for pattern evaluates endpoints for each element

    example.tpzA for pattern evaluates endpoints for each element
    1. import std.io
    2. function high() -> int {
    3. io.writeLine("high")
    4. 1
    5. }
    6. for (0 .. high()) in ([1, 1]) {
    7. io.writeLine("matched")
    8. }
    Expected outputExit code 0
    high
    matched
    high
    matched
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. high
    2. matched
    3. high
    4. matched

    A reached endpoint failure stops matching

    example.tpzA reached endpoint failure stops matchingOpen in Playground →
    1. import std.io
    2. function boom(divisor: int) -> int {
    3. io.writeLine("boom")
    4. 1 / divisor
    5. }
    6. let chosen = match (0) {
    7. case (0 .. boom(0)) => 7
    8. case _ => 9
    9. }
    10. io.writeLine("{chosen}")
    Expected outputNonzero exit
    boom
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    The required primary-location contract is Pending.

    Expected stdout
    1. boom

    Alternatives considered

    • Evaluate all endpoints of an arm before matching. Failure in an unused alternative could interrupt the selected path.
    • Allow only constant endpoints. Existing programs that calculate their range bounds would be rejected.

    Why

    The matching order tells readers which expressions run and which failures can occur.

    Changed rules Integer range patterns →

    A list rest has an explicit pattern

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    A list pattern may use a prefix and ignore the rest. A bare .. leaves it unclear whether a pattern was omitted intentionally.

    Decision

    Always follow .. with a pattern. Use .._ to discard the rest.

    Examples

    Rejecting a rest marker without a pattern

    example.tpzRejecting a rest marker without a patternOpen in Playground →
    1. let count = match ([1, 2]) {
    2. case [..] => 2
    3. }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      list-rest-pattern-required at example.tpz:2:13

    Rejecting an omitted middle rest pattern

    example.tpzRejecting an omitted middle rest patternOpen in Playground →
    1. let total = match ([1, 2, 3]) {
    2. case [first, .., last] => first + last
    3. case _ => 0
    4. }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2001 →

      list-rest-pattern-required at example.tpz:2:20

    Ignoring a rest with an explicit wildcard

    example.tpzIgnoring a rest with an explicit wildcardOpen in Playground →
    1. import std.io
    2. let middle = match ([1, 2, 3, 4]) {
    3. case [first, .._, last] => "{first} {last}"
    4. case _ => "miss"
    5. }
    6. let leading = match ([1, 2, 3, 4]) {
    7. case [.._, last] => last
    8. case _ => 0
    9. }
    10. let trailing = match ([1, 2, 3, 4]) {
    11. case [first, .._] => first
    12. case _ => 0
    13. }
    14. let empty: Array<int> = []
    15. let ignored = match (empty) {
    16. case [.._] if (empty.length == 0) => true
    17. case _ => false
    18. }
    19. io.writeLine(middle)
    20. io.writeLine("{leading}")
    21. io.writeLine("{trailing}")
    22. io.writeLine("{ignored}")
    Expected outputExit code 0
    1 4
    4
    1
    true
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 1 4
    2. 4
    3. 1
    4. true

    Alternatives considered

    • Discard the rest with bare .. only and reject .._. Binding (..rest) and discarding (.._) should follow one rule.
    • Allow both bare .. and .._. There would be two ways to discard the rest.

    Why

    ..rest and .._ share one syntax and show what happens to the remaining items.

    Changed rules A single list rest and its surrounding elements →

    Constructors use parentheses even without arguments

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    If parentheses depend on whether a constructor carries data, readers must look up its declaration. A bare name in a pattern could also be mistaken for a new binding.

    Decision

    • Use parentheses for constructors in values and patterns, as in None(), Empty() and Some(x).
    • Reject a binding that conflicts with a constructor name.

    Examples

    Constructor patterns keep parentheses at every arity

    example.tpzConstructor patterns keep parentheses at every arityOpen in Playground →
    1. import std.io
    2. enum Choice { Empty, Filled(int), Pair(int, int) }
    3. function read(value: Choice) -> int {
    4. match (value) {
    5. case Empty() => 0
    6. case Filled(number) => number
    7. case Pair(left, right) => left + right
    8. }
    9. }
    10. function nested(value: Option<Choice>) -> int {
    11. match (value) {
    12. case None() => -1
    13. case Some(Empty()) => 0
    14. case Some(Filled(number)) => number
    15. case Some(Pair(left, right)) => left + right
    16. }
    17. }
    18. io.writeLine("{read(Choice.Empty())}")
    19. io.writeLine("{read(Choice.Filled(7))}")
    20. io.writeLine("{read(Choice.Pair(2, 3))}")
    21. io.writeLine("{nested(None())}")
    22. io.writeLine("{nested(Some(Choice.Empty()))}")
    Expected outputExit code 0
    0
    7
    5
    -1
    0
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 0
    2. 7
    3. 5
    4. -1
    5. 0

    None needs parentheses in a constructor pattern

    example.tpzNone needs parentheses in a constructor patternOpen in Playground →
    1. function read(value: Option<int>) -> int {
    2. match (value) {
    3. case Some(number) => number
    4. case None => 0
    5. }
    6. }
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2012 →

      pattern-reserved-none-binding at example.tpz:4:14

    None needs parentheses in a constructor value

    example.tpzNone needs parentheses in a constructor valueOpen in Playground →
    1. let maybe: Option<int> = None
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    • TPZ2012 →

      pattern-reserved-none-binding at example.tpz:1:26

    Qualified constructor patterns are rejected

    example.tpzQualified constructor patterns are rejectedOpen in Playground →
    1. enum Choice { Empty }
    2. let value: Choice = Choice.Empty()
    3. let result = match (value) {
    4. case Choice.Empty => 1
    5. }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    The required primary-location contract is Pending.

    A qualified nullary constructor keeps its parentheses

    example.tpzA qualified nullary constructor keeps its parenthesesOpen in Playground →
    1. enum Choice { Empty }
    2. let value: Choice = Choice.Empty()
    Expected outputExit code 0
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Checking accepts the program. Exit code 0.

    Alternatives considered

    • Write nullary constructors as bare names. The role of a name would depend on its declaration and where it was used.
    • Allow both spellings. The same constructor would have two spellings.
    • Require parentheses only in patterns. The same name would look different depending on where it appears.

    Why

    Constructors keep one spelling in both values and patterns, whatever their arity.

    Changed rules Constructor syntax and binding names →Variants without payloads →

    Every match covers all possible values

    Adopted November 9, 2026 · 6.0.0 · In progress

    Problem

    A match over an open type like an integer or a string could omit some inputs. Checks still passed, and execution stopped when one of those inputs arrived.

    Decision

    • The checker requires every match to cover every possible value.
    • Cover all cases of enums, Option, Result, bool and closed unions. Coverage extends to any closed type held inside a constructor.
    • Open types such as integers, floats, strings, arrays, ranges and type parameters require a final unguarded arm.
    • A guarded arm contributes nothing to coverage.
    • Missing coverage produces TPZ5021 during checking. Topaz 6.0.0 retires the runtime diagnostic TPZ4006.

    Examples

    Option bool covers both payloads and None

    example.tpzOption bool covers both payloads and NoneOpen in Playground →
    1. import std.io
    2. function read(value: Option<bool>) -> int {
    3. match (value) {
    4. case Some(true) => 1
    5. case Some(false) => 0
    6. case None() => -1
    7. }
    8. }
    9. let flags = map { "on": true, "off": false }
    10. io.writeLine("{read(flags.get("on"))}")
    11. io.writeLine("{read(flags.get("off"))}")
    12. io.writeLine("{read(flags.get("missing"))}")
    Expected outputExit code 0
    1
    0
    -1
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 1
    2. 0
    3. -1

    Cover all payloads of a constructor with two bool fields →

    Alternatives considered

    • Check closed types and allow open types to fail at runtime. A missing case could pass checking and stop a program on an uncommon input.
    • Specify coverage for bool and leave other types open. Developers would lack a common rule for which arms to write for enums and unions.

    Why

    Checking catches missing cases before the match runs. A match over an open type needs one final unconditional arm that takes every remaining value.

    Changed rules Every match is exhaustive →Reserved runtime code and current checking diagnostic →Non-exhaustive match →

    Resolved pending items Complete exhaustiveness contract →

    For performs effects and a comprehension collects values

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    Putting a loop in a value position used to turn it into array collection. Moving the same loop could change the type of its result.

    Decision

    • A for loop performs effects and returns () in every context.
    • Use a comprehension to collect results into an array.

    Examples

    For results stay unit in grouped and bound positions

    example.tpzFor results stay unit in grouped and bound positions
    1. import std.io
    2. function items(label: string) -> Array<int> {
    3. io.writeLine(label)
    4. [1, 2]
    5. }
    6. let bound = for item in (items("bound")) {
    7. io.writeLine("{item}")
    8. item * 2
    9. }
    10. let grouped = (for item in (items("grouped")) {
    11. io.writeLine("{item}")
    12. item * 3
    13. })
    14. let emptyItems: Array<int> = []
    15. let empty = for item in (emptyItems) { item }
    16. io.writeLine("{bound} {grouped} {empty}")
    Expected outputExit code 0
    bound
    1
    2
    grouped
    1
    2
    () () ()
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. bound
    2. 1
    3. 2
    4. grouped
    5. 1
    6. 2
    7. () () ()

    For cannot supply an array result

    example.tpzFor cannot supply an array result
    1. let values: Array<int> = for item in ([1, 2]) { item * 2 }
    Expected outputNonzero exit
    No stdout.
    $ topaz check example.tpz --language-version 6.0 --format json
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 →

      for-result-type-mismatch at example.tpz:1:26

    Collect values with an array comprehension

    example.tpzCollect values with an array comprehensionOpen in Playground →
    1. import std.io
    2. let values: Array<int> = [for item in ([1, 2]) => item * 2]
    3. io.writeLine("{values[0]} {values[1]}")
    Expected outputExit code 0
    2 4
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 2 4

    Alternatives considered

    • Let for collect an array in value positions. The same loop would do different work depending on where it appears.

    Why

    Readers can tell from the syntax whether the loop collects values or runs for effects. Collecting with an early stop uses an accumulator and break. Collecting without a stop uses a comprehension.

    Changed rules Statement and value uses of for →

    The defer diagnostic asks for a block

    Adopted November 16, 2026 · 6.0.0 · In progress

    Problem

    A rejected defer f() could still produce a message that suggested a bare call. Following that advice did not fix the program.

    Decision

    • During parsing, TPZ2004 says that defer takes a block and points to the start of the body expression.
    • Keep the repair example in the diagnostic's documentation.

    Examples

    Rejecting a deferred call without a block

    example.tpzRejecting a deferred call without a blockOpen in Playground →
    1. import std.io
    2. function finish() -> () {
    3. defer io.writeLine("cleanup")
    4. }
    5. finish()
    Expected outputNonzero exit
    $ topaz check example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during parse. Nonzero exit.

    Alternatives considered

    • Retain the message saying that a block or a call is allowed. The message would recommend a form the language rejects.
    • Put a rewritten example inside the message. The diagnostic description already has the fix, so the same guidance would appear twice.

    Why

    The error tells the reader to put the deferred work in a block.

    Changed rules Registering a deferred block →

    Defer puts deferred work in a block

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    Deferred work could be written as a block or as a bare call. One operation had two spellings.

    Decision

    Follow defer with a block. The parser rejects a bare call such as defer f().

    Examples

    Rejecting a deferred call without a block →

    Running a deferred block at scope exit

    example.tpzRunning a deferred block at scope exitOpen in Playground →
    1. import std.io
    2. function finish() -> () {
    3. defer { io.writeLine("cleanup") }
    4. io.writeLine("body")
    5. }
    6. finish()
    Expected outputExit code 0
    body
    cleanup
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. body
    2. cleanup

    Alternatives considered

    • Keep both blocks and bare calls. The same deferred work would still have two forms.

    Why

    A block makes the boundary of the deferred work visible. The call form evaluated its arguments at registration, not at cleanup. To keep a current value, bind it with let first.

    Changed rules Registering a deferred block →

    Control flow cannot jump across a defer boundary

    Adopted November 19, 2026 · 6.0.0 · Being verified

    Problem

    A return from cleanup can collide with a return already in progress. Previously, an invalid jump could pass checking and report an error only during execution.

    Decision

    • A return, break, continue, or ? crossing a defer body produces TPZ5001 at the expression during checking, even in unreachable code.
    • A return or error propagation inside a function defined in cleanup, and control transfers inside a loop defined in cleanup, are permitted when they stay inside the boundary.
    • Nested cleanup applies the rule at every defer boundary.

    Alternatives considered

    • Assign priorities to jumps during cleanup. A jump could overwrite the return already in progress or conceal another cleanup action.

    Why

    Invalid jumps are caught before execution, and cleanup cannot redirect the surrounding function.

    Changed rules Cleanup order on normal completion and control transfer →Runtime faults skip remaining cleanup →

    Returning an error value still runs registered cleanup

    Adopted November 7, 2026 · 6.0.0 · Being verified

    Problem

    Propagating Err with ? leaves a function before it reaches the end of the block. Registered cleanup needs a defined order on this path.

    Decision

    • When ? returns Err, run defer blocks in reverse registration order in scopes being exited. Ok does not leave a scope.
    • The automatic close from using follows the same exit rule.

    Examples

    Cleaning up scopes during error propagation

    example.tpzCleaning up scopes during error propagationOpen in Playground →
    1. import std.io
    2. function fail() -> Result<int, string> {
    3. io.writeLine("operand")
    4. Err("stop")
    5. }
    6. function finish() -> Result<int, string> {
    7. defer { io.writeLine("outer") }
    8. let value = {
    9. defer { io.writeLine("inner-first") }
    10. defer { io.writeLine("inner-second") }
    11. fail()?
    12. }
    13. io.writeLine("unreachable")
    14. Ok(value)
    15. }
    16. io.writeLine(match (finish()) {
    17. case Ok(value) => "value={value}"
    18. case Err(error) => error
    19. })
    Expected outputExit code 0
    operand
    inner-second
    inner-first
    outer
    stop
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. operand
    2. inner-second
    3. inner-first
    4. outer
    5. stop

    Alternatives considered

    • Skip defer when ? propagates an error. The same cleanup would behave differently on a structured early return.
    • Clean up only using as a special case. Cleanup needs one rule however the scope is left.

    Why

    One registration covers ordinary and structured exits from its scope.

    Changed rules Cleanup order on normal completion and control transfer →Using acquisition and cleanup order →

    An unrecoverable runtime fault skips remaining cleanup

    Adopted November 9, 2026 · 6.0.0 · Being verified

    Problem

    A program can still have cleanup registered when it stops with a runtime fault. Cleanup can print or fail in its own right.

    Decision

    An ordinary runtime fault terminates execution and cannot be caught to resume it. Skip remaining defer and using cleanup.

    Examples

    A runtime fault leaves defer output absent

    example.tpzA runtime fault leaves defer output absentOpen in Playground →
    1. import std.io
    2. function divide(divisor: int) -> int {
    3. defer { io.writeLine("cleanup") }
    4. io.writeLine("before fault")
    5. 12 / divisor
    6. }
    7. io.writeLine("{divide(0)}")
    Expected outputNonzero exit
    before fault
    
    $ topaz run example.tpz --language-version 6.0
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    Expected stdout
    1. before fault

    Alternatives considered

    • Continue running cleanup after the fault. New output or a second failure could follow the first fault.
    • Leave cleanup during a fault unspecified. The behavior must be fixed so the same program repeats its output.

    Why

    Readers can identify the fault at which execution stops.

    Changed rules Runtime faults skip remaining cleanup →

    Partly answered pending items Pending: complete defer contexts and abrupt exits →

    Version history