Lyricdev
GitHub

LYR-SEM0075

a 'var' that is never reassigned

warning · spec 07-statements · lint unused-var, group unused, warn unless said

A var with an initializer is read but never reassigned, written through, or used for a mut fn call; let would do.

Explanation

A var says the binding changes. One that never does reads as a promise the code does not keep, and a reader looks for the change that is not there.

Write let. A var that documents a change through it — a field write, a mut fn call — is not reported.

Wrong

import std.io { println };

fn main(): void {
    var count = 3;
    println(count);
}
import std.io { println };

fn main(): void {
    let count = 3;
    println(count);
}