diff --git a/crates/grain/src/lib.rs b/crates/grain/src/lib.rs index 532f8c7cb..24af8f034 100644 --- a/crates/grain/src/lib.rs +++ b/crates/grain/src/lib.rs @@ -2492,7 +2492,10 @@ impl Bindgen for FunctionBindgen<'_, '_> { self.push_str("for (let mut i = WasmI32.(-)("); self.push_str(&len); - self.push_str(", 1n); WasmI32.gtU(i, 0n); i = WasmI32.(-)(i, 1n)) {\n"); + // We loop from the end of the list to the start, + // because wasm is unsigned when we hit `0` we'll loop back around to `-1` + // and exit the loop. + self.push_str(", 1n); WasmI32.(!=)(i, -1n); i = WasmI32.(-)(i, 1n)) {\n"); self.push_str("let base = WasmI32.(+)("); self.push_str(&base); self.push_str(", WasmI32.(*)(i, ");