Skip to content
ZOLO / TE166 Type · error

invalid typed string-capture pattern or conversion

Compiler diagnostic TE166: invalid typed string-capture pattern or conversion.

Use a pattern literal to match a complete string and bind checked scalar values:

match input {
    pat"order/{id: int}/{status: str}" if id > 0 => print(id, status),
    _ => print("invalid order"),
}

Each capture needs a unique binding name and an explicit supported type. Give adjacent captures a literal separator: pat"{id: int}/{status: str}", rather than pat"{id: int}{status: str}". The scrutinee must have a proven string type; an Any value is not evidence of that type. Unknown aliases, unsupported scalar types and unproved nominal constructors receive a positioned diagnostic.

Type aliases retain their actual scalar type. Validated newtypes use their real checked constructor; an invalid value makes the pattern fail. Captures are published only after every literal and conversion succeeds, in that arm or successful condition's scope. They do not leak into later arms or outer scopes.

Matching anchors both ends of the string. A literal delimiter selects its first occurrence, left to right, without backtracking; a final capture takes the remaining text. Parsing failure is a non-match, not a panic. Include a fallback arm because typed captures remain refutable, including when guarded.

Write {{ and }} for literal braces inside a pattern literal. Ordinary string patterns keep their established equality semantics. The attached pat"..." form belongs to pattern positions; pat remains an ordinary name.

See pattern matching and the runnable example.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

en