Lyricdev
GitHub

LYR-SEM0208

an integer literal that takes another type than int

warning · spec 03-types · lint int-literal-adapts, group correctness, allow unless said

An integer literal without a suffix takes a type other than int from its context. Not said unless the lint is set to warn.

Explanation

A literal adapts to the type its context names, and a reader may not see which type that is. Turning the lint on asks for the type to be written where a literal takes one.

Write the suffix (3u8) or keep the literal in a context that names the type plainly. The lint is allow by default.

Wrong

@Warn("int-literal-adapts")
fn main(): void {
    let small: uint8 = 3;
    let _ = small;
}
@Warn("int-literal-adapts")
fn main(): void {
    let small = 3u8;
    let _ = small;
}