style: migrate arrow-block lambdas () => { .. } to () { .. }
The canonical sx block-body lambda is `(params) { stmts }` (and
`(params) -> Ret { stmts }`); the arrow form `=>` is for EXPRESSION bodies
(`(params) => expr`). The arrow-block hybrid `(params) => { .. }` was being
used in 33 files — convert all of them by dropping the `=>`. The two forms are
exactly equivalent (verified: identical IR and identical runtime values — the
block tail is the value with or without a `-> Ret`), so this is a pure source
cleanup: no `.ir` churn, and the only snapshot change is 0923's diagnostic
COLUMN (a negative narrowing test whose error span shifted by the removed `=> `).
Arrow EXPRESSION bodies (`=> expr`, `=> .{..}`, `=> [..]`) and `=>` inside
comments/strings were left untouched. Migrated across examples/concurrency,
examples/{closures,ffi-objc,generics,optionals,types}, issues/, and the stdlib
(io.sx, sched.sx). Suite 855/0.
This commit is contained in:
@@ -10,7 +10,7 @@ Ctx :: struct {
|
||||
}
|
||||
|
||||
main :: () -> i32 {
|
||||
c : Ctx = .{ on = (f: Fmt) => {
|
||||
c : Ctx = .{ on = (f: Fmt) {
|
||||
n : i64 = xx f;
|
||||
print("cl f = {}\n", n);
|
||||
}};
|
||||
|
||||
@@ -31,7 +31,7 @@ ticks : i32 = 0;
|
||||
|
||||
main :: () -> i32 {
|
||||
h : Holder = .{};
|
||||
h.set(() => { ticks += 1; });
|
||||
h.set(() { ticks += 1; });
|
||||
|
||||
h.call_direct();
|
||||
h.call_hoisted();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#import "modules/std.sx";
|
||||
|
||||
main :: () {
|
||||
pick := (p: ?i64) -> i64 => {
|
||||
pick := (p: ?i64) -> i64 {
|
||||
if p == null { return -1; }
|
||||
return p; // narrowed inside the lambda body
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// the call types as `unresolved` (so `catch`/`try` reject it).
|
||||
//
|
||||
// Regression (PLAN-IO-UNIFY Phase 3 blocker): the async completion closure
|
||||
// `() => { f.value = worker() catch {…} }` captures a `Closure() -> ($R, !)`
|
||||
// `() { f.value = worker() catch {…} }` captures a `Closure() -> ($R, !)`
|
||||
// worker and consumes its error channel — exactly this shape.
|
||||
#import "modules/std.sx";
|
||||
|
||||
@@ -15,7 +15,7 @@ Box :: struct { run: Closure() -> void; }
|
||||
// `catch` path: the nested closure absorbs the worker's error.
|
||||
run_catch :: (worker: Closure() -> (i64, !)) {
|
||||
b : Box = ---;
|
||||
b.run = () => {
|
||||
b.run = () {
|
||||
v := worker() catch {
|
||||
print("caught\n");
|
||||
return;
|
||||
@@ -27,17 +27,17 @@ run_catch :: (worker: Closure() -> (i64, !)) {
|
||||
|
||||
// `try` path: the nested closure is itself failable and propagates.
|
||||
mk_trier :: (worker: Closure() -> (i64, !)) -> Closure() -> (i64, !) {
|
||||
return () -> (i64, !) => {
|
||||
return () -> (i64, !) {
|
||||
v := try worker();
|
||||
v + 100
|
||||
};
|
||||
}
|
||||
|
||||
main :: () -> i64 {
|
||||
run_catch(() -> (i64, !) => { 7 }); // ok 7
|
||||
run_catch(() -> (i64, !) => { raise error.Bad; }); // caught
|
||||
run_catch(() -> (i64, !) { 7 }); // ok 7
|
||||
run_catch(() -> (i64, !) { raise error.Bad; }); // caught
|
||||
|
||||
t := mk_trier(() -> (i64, !) => { 5 });
|
||||
t := mk_trier(() -> (i64, !) { 5 });
|
||||
r := t() catch { return 1; };
|
||||
print("try {}\n", r); // try 105
|
||||
return 0;
|
||||
|
||||
@@ -28,7 +28,7 @@ main :: () -> i64 {
|
||||
b : CB = ---;
|
||||
b.add = (x: i64, y: i64) => x + y;
|
||||
b.fp = triple;
|
||||
b.work = (n: i64) -> (i64, !) => {
|
||||
b.work = (n: i64) -> (i64, !) {
|
||||
if n < 0 { raise error.Negative; }
|
||||
n * 10
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user