Skip to content

Commit 367197d

Browse files
fix(stdlib): declare reassigned locals in io.affine as let mut (#128) (#189)
printf/path_join/path_dirname/path_extname/read_lines reassigned loop counters and accumulators (arg_idx, i, result, parts, done) that were declared with plain let -> borrow error. Pure stdlib bug, not a compiler bug. stdlib 15->16/19; 233/233 dune test, zero regression. Refs #128 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a3b1cae commit 367197d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

stdlib/io.affine

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use string::{ split, join };
3838
/// printf("Hello, {}! You are {} years old.", ["Alice", 30])
3939
fn printf(format: String, args: [Any]) -> () {
4040
let flen = len(format);
41-
let arg_idx = 0;
42-
let i = 0;
41+
let mut arg_idx = 0;
42+
let mut i = 0;
4343

4444
while i < flen {
4545
if i + 1 < flen && string_sub(format, i, 2) == "{}" {
@@ -124,7 +124,7 @@ extern fn remove_dir(path: String) -> Result<(), String>;
124124

125125
/// Join path components with the system separator (/)
126126
fn path_join(components: [String]) -> String {
127-
let result = "";
127+
let mut result = "";
128128
let mut first = true;
129129
for component in components {
130130
if first {
@@ -143,7 +143,7 @@ fn path_join(components: [String]) -> String {
143143
/// Example: path_extension("file.txt") => Some("txt")
144144
fn path_extension(path: String) -> Option<String> {
145145
let plen = len(path);
146-
let i = plen - 1;
146+
let mut i = plen - 1;
147147
while i >= 0 {
148148
let ch = string_get(path, i);
149149
if ch == '.' {
@@ -170,7 +170,7 @@ fn path_filename(path: String) -> String {
170170
if plen == 0 {
171171
return "";
172172
}
173-
let i = plen - 1;
173+
let mut i = plen - 1;
174174
while i >= 0 {
175175
if string_get(path, i) == '/' {
176176
return string_sub(path, i + 1, plen - i - 1);
@@ -189,7 +189,7 @@ fn path_dirname(path: String) -> String {
189189
if plen == 0 {
190190
return ".";
191191
}
192-
let i = plen - 1;
192+
let mut i = plen - 1;
193193
while i >= 0 {
194194
if string_get(path, i) == '/' {
195195
if i == 0 {
@@ -209,7 +209,7 @@ fn path_dirname(path: String) -> String {
209209
fn path_stem(path: String) -> String {
210210
let filename = path_filename(path);
211211
let flen = len(filename);
212-
let i = flen - 1;
212+
let mut i = flen - 1;
213213
while i > 0 {
214214
if string_get(filename, i) == '.' {
215215
return string_sub(filename, 0, i);
@@ -239,8 +239,8 @@ extern fn chdir(path: String) -> Result<(), String>;
239239

240240
/// Read all input from stdin until EOF
241241
fn read_stdin() -> Result<String, String> {
242-
let parts = [];
243-
let done = false;
242+
let mut parts = [];
243+
let mut done = false;
244244
while !done {
245245
match read_line() {
246246
Ok(line) => {

0 commit comments

Comments
 (0)