Replace the bare-paren tuple grammar with explicit, position-unambiguous
forms, mirroring how structs work:
type `(A, B)` -> `Tuple(A, B)` (named keeps `:`)
value `(a, b)` -> `.(a, b)` (named uses `=`)
typed (new) -> `Tuple(A, B).(a, b)` (like `Point.{...}`)
failable `-> (T, !)` -> `-> T !`
`-> (T1, T2, !)`-> `-> Tuple(T1, T2) !` (channel outside Tuple)
Bare `(...)` is now grouping only, everywhere; a comma in bare parens is a
hard error with a migration hint. Grouping, function types `(A, B) -> R`,
param lists, lambdas, and match bindings are unaffected.
`Tuple(...)` is strictly a TYPE in every position (including `size_of` /
`type_info` args); a tuple VALUE comes only from `.(...)` (anonymous) or
`Tuple(...).(...)` (explicitly typed). A bare `Tuple(1, 2)` is a tuple
type with non-type elements -> rejected.
The ~110 tuple-bearing corpus files were migrated with a one-shot
AST-aware migrator (the `sx migrate` tool from the prior commit, removed
here). New examples: 0130 (new syntax), 0131 (typed construction), 1060
(named-tuple failable return). 1116 golden updated for the new hint text.
36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
// Rejection counterpart to 1046 (ERR step E1.8). Reading a failable's value slot
|
|
// where its error is NOT proven absent is a compile error. Two unproven shapes:
|
|
//
|
|
// (A) reading the value inside the `if err { … }` error path itself
|
|
// (B) reading the value after a bare tag-compare (`if err == error.X`), which
|
|
// narrows the tag but proves nothing about absence
|
|
//
|
|
// Each read is rejected with the E1.8 diagnostic; the program never runs (exit 1).
|
|
|
|
#import "modules/std.sx";
|
|
|
|
E :: error { Bad }
|
|
|
|
parse :: (n: i32) -> i32 !E {
|
|
if n < 0 { raise error.Bad; }
|
|
return n * 10;
|
|
}
|
|
|
|
// (A) the read sits on the error path — `err` is present here, not absent.
|
|
bad_a :: () -> i32 {
|
|
v, err := parse(5);
|
|
if err { return v; } // REJECTED: err present on this path
|
|
return 0;
|
|
}
|
|
|
|
// (B) a tag-compare narrows which error, but does not prove there is none.
|
|
bad_b :: () -> i32 {
|
|
v, err := parse(5);
|
|
if err == error.Bad { return 1; }
|
|
return v; // REJECTED: err not proven absent
|
|
}
|
|
|
|
main :: () -> i32 {
|
|
return bad_a() + bad_b();
|
|
}
|