Skip to content
ZOLO / TE837 Type · error

numeric cast may lose information

A numeric `as` may narrow a range, change signedness, discard a fractional part, or round an integer too large for the destination float. Use `as?` when only an exact value is acceptable, or `cast` with a named rounding/overflow policy when loss is intentional.

Why this fires

A numeric as may narrow a range, change signedness, discard a fractional part, or round an integer that is too large for the destination float.

let byte = large as u8 // warning[TE837]

Fix it

Use as? when only an exact value is acceptable:

if let byte = large as? u8 {
    send(byte)
}

When loss is intentional, use cast with a named rounding/overflow policy.

See also

  • TE836 — checked cast has no valid path.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br