Skip to content
Topazdocs
6.05.21

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

    Tools

    Language changes from Topaz 5.21 to 6.0

    Review changes in execution results and find manual source fixes by syntax or diagnostic.

    Language mode
    6.0
    Product
    Not released

    Using the checklist

    Review the execution results section even if your source passes the 6.0 check. The comparisons follow the language rules and the interpreter source for both editions. Later sections link to diagnostics and examples for source changes.

    Follow the 6.0 alpha migration guide to preview and check your code. The design decision record shows the implementation status of each rule.

    Same source, different execution results

    • Arrays, maps and sets change independently after assignment, argument passing, return or field storage. For example, let a = [1, 2], let mut b = a and b.push(3) leave lengths 3:3 in 5.21 and 2:3 in 6.0. Look for a collection stored in a second binding or field, followed by an indexed write or a method such as push, insert or add. If callers need the updated value, return it and assign it where it is used. Mutable closures can still share a variable. Open files still use shared resource handles. Decision · Example
    • An indexed assignment writes to the collection currently held by its binding after the right-hand side runs. If shrink() rebinds xs to [7] and returns 5, then xs[0] = shrink() leaves xs as [7] in 5.21 and [5] in 6.0. Look for indexed writes whose right-hand sides call a function that can rebind the target. Make the order explicit with separate statements when both changes are intentional. Decision · Example
    • Float interpolation and derived display keep a fractional digit even for large integral floats. Interpolating 1000000000000000.0 yields 1000000000000000 in 5.21 and 1000000000000000.0 in 6.0. Look for interpolated floats and derived display output used in snapshots, text comparisons or file formats. Review consumers that require a particular spelling. Decision · Example
    • Inside a multiline literal, a source line containing only spaces or tabs keeps those bytes in 5.21. In 6.0 it contributes an empty line. Look inside """ literals for lines made only of spaces or tabs, especially in byte comparisons and templates. Use escapes or interpolation for whitespace that belongs in the resulting text. Decision · Example
    • A physical lone CR inside multiline string text can survive in 5.21 as a carriage return. In 6.0 it becomes a newline, just like CRLF and LF. Search source files for byte 0D without a following 0A inside """ literals. Write \r as an escape in an ordinary string when the resulting data needs a carriage return. Decision · Example

    Comments, names and literals

    Expressions and control flow

    • Add parentheses around control operands and guards, as in if (test), while (test) and match (value). The migrate preview can add these parentheses where the 5.21 parser records an unparenthesized control operand. Decision · TPZ2001 · Example
    • Remove unary + and keep the operand, as in +1 → 1 and +value → value. Decision · TPZ2001 · Example
    • Replace pipelines and expression placeholders with ordinary calls. For value |> f(arg, _), save value in a let before calling f(arg, saved). For composition, save the two function values in order as first and second, then use (x) => second(first(x)). Decision · TPZ2001 · Example
    • An if without else yields (). If the enclosing expression needs a value, supply an else branch with a compatible type, as in if (test) { 7 } else { 0 }. Decision · TPZ5001 · Example
    • A for loop returns (). To collect the loop results into an array, write a comprehension such as [for item in (items) => item * 2]. Decision · TPZ5001 · Example
    • Give defer a block. Rewrite defer f() as defer { f() }. Decision · TPZ2004 · Example
    • Move a return, break, continue or ? that exits a defer body outside the cleanup block. Handle cleanup errors inside the block if the cleanup itself can fail. Decision · TPZ5001 · Example

    Patterns and match arms

    • Wrap range patterns by hand, as in case (1 .. 3) => 1. The automatic edit for control operands does not wrap range patterns. Decision · TPZ2001 · Example
    • Write the argument list for a constructor in both values and patterns, even when it is empty. Replace bare None with None() and write a qualified variant as Choice.Empty(). Decision · TPZ2012 · Example
    • Write each record pattern field as field: pattern. Replace {x} with {x: x} to bind a field to a name with the same spelling. Decision · TPZ2001 · Example
    • Give .. in a list pattern a following pattern. To ignore the remainder, use .._, as in [first, .._]. Decision · TPZ2001 · Example
    • Use a block when a match arm returns from the enclosing function. Rewrite case true => return 7 as case true => { return 7 }. Decision · TPZ2001 · Example
    • Cover every possible input, including cases inside constructor payloads. Add explicit cases for missing values or a final unguarded case _ for the remainder. A guarded arm does not establish coverage. Decision · TPZ5021 · Example
    • Remove an arm fully covered by earlier unguarded arms. If it should handle a special case, place the specific case before the broader one. Arms are tried in source order. Decision · TPZ5713 · Example
    • Remove a literal range pattern that can never match, or fix its bounds. For example, (0 ..< 0) is empty and (0 .. 0) matches zero. Decision · TPZ5714 · Example

    Functions and calls

    • Parenthesize every lambda parameter list. Rewrite x => x + 1 as (x) => x + 1. Decision · TPZ2001 · Example
    • Pass arguments in parameter order. If reordering would change when an argument expression runs, evaluate the expressions in their original order into local names first. To keep independent options named, change the function to take a settings record. Decision · TPZ2001 · Example
    • identity<int> (1) and identity<int>(1) both parse as calls with type arguments. Remove the type arguments for a non-generic function, as in identity(1). If you intended a comparison, use parentheses to make the comparison explicit. Decision · TPZ5512 · Example
    • Give repeated parameters in one function or lambda different names. Update references in the body to the intended parameter. Decision · TPZ5008 · Example
    • Remove the default from a variadic parameter, as in ...values: int. If an empty argument list should use fallback values, select them explicitly when the collected array is empty. Decision · TPZ2001 · Example
    • For a field or method read on an unconstrained generic parameter, declare the required operation in a protocol. Add a bound such as T: Readable and use Readable.read(value). Decision · TPZ5006 · Example
    • A call through a union needs each argument to have one type accepted by every possible callee. Add a type annotation if the branches accept a common type but inference lacks context. If the branches require different callback types, narrow the union first and make a separate call in each case. Decision · TPZ5020 · Example

    Bindings, constructors and updates

    • Keep one type annotation for a binding. Replace let answer: int: int = 1 with let answer: int = 1. Decision · TPZ2001 · Example
    • A local function shadows an outer name throughout the block. For a direct call before the local declaration, put the declaration first. If that call was meant to reach an outer function, give the local function a distinct name. Decision · TPZ3018 · Example
    • Rename bindings, parameters or functions that share a name with a visible constructor, and update their uses. For an imported constructor, check its name as seen in the importing module, including any alias. Decision · TPZ5712 · Example
    • To construct a value, write a call such as Choice.Full(value). To pass the operation as a function value, wrap that call in a lambda, as in (value) => Choice.Full(value). Decision · TPZ5004 · Example
    • Write each field once per structural record update. If earlier field expressions must still run, evaluate them separately in their intended order before writing the final field value. Decision · TPZ5008 · Example
    • When you need to retain a changed value, bind it with let mut before calling the mutator. When you need the return value of a call on a temporary, use it, as in let last = make().pop(). Decision · TPZ5027 · Example
    • To call a mutating method later, store a lambda that calls it on a mutable binding, as in let add = (v) => xs.push(v). The receiver is accessed when the lambda runs. Decision · TPZ5028 · Example
    • For a write such as xs?.push(2), make the root binding mutable. To start from an immutable parameter or loop variable, first copy its value into a mutable local binding. Decision · TPZ5003 · Example

    Protocols

    • Remove the type parameter from protocol declarations such as protocol Labelled<T>. In the protocol method signatures, write Self where T named the conforming type. Keep naming the concrete type in impl Labelled<Item>. Decision · TPZ2001 · Example
    • Remove parameter defaults and per-method export from protocol implementations. Keep any default in the protocol declaration if it belongs to the common interface. For a fallback specific to one caller, pass it explicitly at that call site. Decision · TPZ5022 · Example

    Imports, errors and concurrency

    • Remove as when it repeats the imported name. For example, replace import lib as lib with import lib. Decision · TPZ2009 · Example
    • To change an imported array locally, copy its value with let mut localItems = items and update localItems. That changes the local value. Decision · TPZ5003 · Example
    • When a record field default reads a name in another module, use an exported name. For example, if defaults.seed belongs in that module’s public interface, declare export let seed: int = 41 in defaults. Decision · TPZ3009 · Example
    • Use public types in exported signatures, including types inferred from function bodies or expanded from aliases. Export a nominal type if it belongs to the public interface. Otherwise, return or accept a public representation at the boundary. Decision · TPZ3014 · Example
    • When the checker cannot infer the error type of a Result, annotate the return type with the intended error type. For example, a function that returns Ok(1) can declare -> Result<int, string> if it uses string errors. Decision · TPZ5022 · Example
    • Have a concurrent arm produce a result value. Handle an enclosing function return, loop transfer or error propagation after the group instead of transferring control out of the arm. Decision · TPZ5001 · Example
    • An empty concurrent {} group yields an empty record. If you need its result, use the record type {}. If the surrounding expression needs unit, discard the group result and produce () explicitly. Decision · TPZ5001 · Example