Define overlap behavior for path copy and join outputs
Problem
Path APIs return success while corrupting valid inputs when the destination overlaps an input. No consistent overlap rule is enforced.
Reproduction and evidence
Audited canonical master 69a67c6e0fb700f37ee6114f5a66d37ee13771a5 (0.0.1-alpha-dev). Matching checkout-built compiler/std were used for compiler probes on Linux amd64 with Rust 1.89.0 and LLVM 21.1.8. Artifact inspection, mocked/projection checks and foreign-target object emission are identified below and are not native execution on those operating systems.
import("std::path::copy")::{path_join2,path_basename_copy};
fun main()->i32{
var b:array<u8,64>;
b[0]=102;b[1]=105;b[2]=108;b[3]=101;b[4]=0;
var count:i32=path_join2(&b[0],64,"/base",&b[0] as str);
println("join={} text={s}",count,&b[0] as str);
b[0]=97;b[1]=98;b[2]=99;b[3]=0;
count=path_basename_copy(&b[1],63,&b[0] as str);
println("base={} text={s}",count,&b[1] as str);
return 0;
}
target/debug/wavec --std-root "$PWD/std" build repro.wave -O0 --run --out-dir out-O0
target/debug/wavec --std-root "$PWD/std" build repro.wave -O2 --run --out-dir out-O2
O0/O2: join returns 10 with /base//bas instead of /base/file; basename_copy(dst=src+1) returns 3 with aaa instead of abc. Buffers are real 64-byte arrays.
Scope
Set one explicit overlap contract for join/basename/dirname and enforce it before mutation or use an approved staging strategy.
Starting points: std/path/copy.wave:35, std/path/copy.wave:104.
Design discussion required
Recommended bounded policy: reject input/output overlap before writing; alternatively specify supported exact aliases or use stable staging for overlap. Decide buffer ownership, allocation and failure preservation before implementation. The separate C-string overlap policy does not automatically define path API semantics.
Please mention @LunaStev to discuss the design before starting implementation.
Completion criteria
- [ ] Permitted overlap yields the same result as disjoint inputs.
- [ ] Rejected overlap returns the approved error before any source/destination mutation.
- [ ] Cover exact aliases and partial overlap in both directions without one issue per function.
Related: #1043, #1039. Related broad trackers or completed implementations are context, not claims that their entire scope is unfinished.