emitSubslice handled a struct (slice/string) base and an array base, but a many-pointer [*]T base is an LLVM pointer kind — it fell through to the else arm that mapped the result to LLVMGetUndef(slice_ty), so a slice of a many-pointer (mp[lo..hi]) had a garbage .len/.ptr and iterating it segfaulted. Add a LLVMPointerTypeKind branch: the base value IS the data pointer, so GEP by lo and len = hi - lo (the caller supplies the bound; no length is read from the unbounded pointer). An open-ended mp[lo..] has no resolvable upper bound (a [*]T carries no length), so lowerSliceExpr now diagnoses it instead of emitting a .length op that yields garbage. A List (whose items is [*]T) is now iterable with for items[0..len] (e); applied in Scheduler.deinit. Regressions: examples/types/0195 (valid slice + List for-each) + examples/diagnostics/1192 (open-ended rejection).
13 lines
507 B
Plaintext
13 lines
507 B
Plaintext
// Slicing a many-pointer `[*]T` requires an explicit upper bound — it carries
|
|
// no length, so an open-ended `mp[lo..]` has no bound to resolve and would
|
|
// otherwise build a garbage-length slice. This guards that diagnostic.
|
|
// (Companion: examples/types/0195 covers the valid explicit-bound form.)
|
|
#import "modules/std.sx";
|
|
|
|
main :: () -> i64 {
|
|
a : [4]i64 = .[5, 6, 7, 8];
|
|
mp : [*]i64 = xx @a[0];
|
|
s := mp[1..]; // ERROR: many-pointer slice needs an explicit hi
|
|
return s.len;
|
|
}
|