Home / Docs / Diagnostics

U4008: A text literal with interpolation in a pattern

Release v0.4.0

A pattern holds a text literal with interpolation. U4008 reports it in every edition.

Why Una rejects it

A pattern's literal is a constant: a when arm is "…" and the expression x is "…" compare a value with it (spec/10 §4).

A text literal with interpolation, such as "{s}", is not a constant: its text is computed from the values it interpolates, and those can be labeled. Testing a value against it would decide a branch, or a Bool, by those values without their labels (spec/07 §7 rule 3), so U4008 reports it, in every edition.

How to fix it

The repair at a glance

src/demo.unadiff
  module demo

- pub matches(name: Text, other: secret Text) -> Bool = name is "{other}"
+ pub matches(name: Text, other: secret Text) -> secret Bool = name == other

Failing example

src/demo.unauna
module demo

pub matches(name: Text, other: secret Text) -> Bool = name is "{other}"

Fixed example

src/demo.unauna
module demo

pub matches(name: Text, other: secret Text) -> secret Bool = name == other