docs

#E0114: invalid literal handler

A #[literal(..)] handler must be a function with the parameters its kind takes, registered once per suffix, priority and return type. A number suffix or string prefix is a name glued to the literal (95pct, date"2024-01-15"), never a symbol such as % or °, and a suffix can't start with e or _, which read as an exponent and a digit separator. A suffixed or prefixed literal needs a handler for it in scope; the message names the closest one there is.

nabi
let d = 5q;
error[E0114]: unknown numeric literal suffix `q` - no `#[literal(number "q")]` handler is registered
  --> main.nabi:1:10
   |
 1 | let d = 5q;
   |          ^
   |
   = help: register one, `#[literal(number "q")] fn ..`, here or as a `pub fn` in a package this one depends on; the suffixes in scope are `i`

Register a handler for the suffix; the literal becomes a call to it (6.5):

nabi
#[literal(number "q")]
fn quarter(n: f64) -> f64 { n / 4.0 }

let d = 5q;
println(f"{d}");
1.25

A suffix or prefix that is a near miss of one in scope gets a "did you mean" and a quick fix: with signal as a dependency, 10Hz says did you mean `10hz`?, and with table, dat"2024-01-15" says did you mean `date`?. A percentage is a suffix name, not %, which is the remainder operator:

nabi
let p = 95%;        // error: `95%` is not a percentage; write `95pct`
#[literal(number "°")]   // error: a number suffix is a name, and `°` is a symbol
const fn deg(n: f64) -> f64 { n }

Register a name instead: #[literal(number "deg")], then write 90deg.

Related: E0003 malformed numeric literal, E0123 registered twice

Found a mistake? Edit this page on GitHub. Last updated