Traps & Differences
These are the mistakes that cost agents the most in our trials. They are in the miri-lang pack, and
are worth a read before you review Miri code an agent wrote.
Where Miri differs
- Bindings are
let(immutable) andvar(mutable); there is nolet mut. Parameters are immutable too; mutate a collection argument with.set(i, v). - Types follow the name with a space:
let x int = 5,fn f(a int) int. No:before a type, no->, no literal suffixes (42i32); cast withas. - Logic is
and,or,not. Nullable isT?with bareSome/None;Resultpatterns need the prefix:Result.Ok(v),Result.Err. List([1, 2])builds from a literal,List<int>()is empty,Map<K, V>()andSet<T>()likewise.[1, 2, 3]alone is a fixedArray;{}is aMap.- A
forover aMapwalks its keys; there is no.keys(). - An f-string is the only int → String conversion:
f"{n}", nevern.to_string()or"n=" + n. main() intreturns an exit status;panic(message)stops with status 1. There is noexit.- Stdlib modules are imported by name (
use system.collections.list).
Traps
- Quotes inside f-string braces must be the other quote character:
f"{m['a']}". The same quote ends the string (MER_LEX_012). - Positions count characters, in
length(),substring,element_at,code_atand regex matches alike; onlysize()counts bytes. Asubstringrange outside the text stops the program (or fails to compile, if constant). - Integer overflow stops the program (
MER_RT_003) instead of wrapping. Where wrapping is meant — a hash, a checksum — writewrapping_add,wrapping_suborwrapping_mulfromsystem.math. - Walk with
for, not by position.for ch in sandfor k in mare one pass; indexing aString,MaporSetby a counter repeats lookups. - Every statement lives in a function. A statement beside
mainnever runs and is refused (MER_TYP_069); put the script’s body insidemain. - Integer widths do not convert implicitly. An
intvalue stored into ani32/u32slot, element or field needsas i32; the same holds betweenfloatandf32.miri fix --applywrites the cast. - Format specs follow Python:
f"{x:.2f}",f"{n:>8}",f"{n:08x}". A precision needsf({x:.2}is refused);x/b/otake integers only. - Imports are explicit. A name from another module needs its
useline;miri fix main.mi --apply --yesadds one that resolves in exactly one module.