Sisu
E0134

Interpolation in a string pattern

Error

Built from the repository at commit a8614dc.

A string pattern matches one string as written, so it takes no interpolation: "{x}" is not a pattern.

Why

A pattern compares with values known when the program compiles. An interpolation is computed when the program runs, and in some languages a pattern like "{x}" would bind x to part of the string instead. Bind the string and compare it in a guard.

Broken

fn greet(s: string, name: string) -> bool {
    match s {
        "hello {name}" => true
        _ => false
    }
}

fn main() {
    print(greet("hello Ada", "Ada"))
}

What sisu says

error[E0134]: a pattern takes no interpolation
 --> E0134.sisu:3:16
  |
3 |         "hello {name}" => true
  |                ^^^^^^

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0134

Fixed

fn greet(s: string, name: string) -> bool {
    match s {
        t if t == "hello {name}" => true
        _ => false
    }
}

fn main() {
    print(greet("hello Ada", "Ada"))
}