feat: struct and tuple patterns in match (bootstrap + selfhost)
Support destructuring in match arms:
- Tuple: (a, b) binds subject._0 / _1
- Struct: Point { x: px, y: py } and shorthand Point { x, y }
Bootstrap: matchPatternBindings for pkTuple/pkStruct; register local
tuple typedefs from function bodies. Selfhost: parse, Sema_BindPattern,
Lcx_PatternBindings with scope defines. Fix operator-overload path that
crashed when typeName was null after pattern binds.
Example: examples/struct_tuple_pat.bux. Selfhost-loop IDENTICAL.
This commit is contained in:
+14
-1
@@ -383,7 +383,20 @@ Supported patterns:
|
||||
- Identifier catch-all: `name` (binds whole subject)
|
||||
- Range: `1..9`, `1..=9`
|
||||
- Enum tags + **payload bindings**: `Option::Some(value)`, `Pair::Two(a, b)`
|
||||
- Struct / tuple / guard patterns: parsed; full lowering still evolving
|
||||
- **Tuple patterns**: `(a, b)` → binds `subject._0`, `subject._1`
|
||||
- **Struct patterns**: `Point { x: px, y: py }` or shorthand `Point { x, y }`
|
||||
- Guard patterns: parsed; full lowering still evolving
|
||||
|
||||
```bux
|
||||
match pair {
|
||||
(a, b) => a + b,
|
||||
_ => 0
|
||||
}
|
||||
match p {
|
||||
Point { x, y } => x * 10 + y,
|
||||
_ => -1
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
+15
-3
@@ -261,9 +261,21 @@ A (stdlib ergonomics) → B (compiler holes) → C (ownership depth)
|
||||
|
||||
---
|
||||
|
||||
## Сесия 15 (struct/tuple patterns)
|
||||
|
||||
1. **Tuple patterns:** `match t { (a, b) => a + b }` — bind `subject._0` / `._1`
|
||||
2. **Struct patterns:** `Point { x: px, y: py }` + shorthand `Point { x, y }`
|
||||
3. Bootstrap: `matchPatternBindings` for pkTuple/pkStruct; field types from struct decl; range registration of local tuple typedefs
|
||||
4. Selfhost: parse `()` / `Name { … }` patterns; `Sema_BindPattern` + `Lcx_PatternBindings` with Scope_Define
|
||||
5. Fix: operator-overload path treated `String_Eq(null, "")` as non-empty → crash on `a + b` after pattern bind
|
||||
6. Example: `examples/struct_tuple_pat.bux`
|
||||
7. Verified: bootstrap + **buxc2** + selfhost-loop IDENTICAL ✓
|
||||
|
||||
---
|
||||
|
||||
## Следващи стъпки
|
||||
|
||||
1. Struct/tuple patterns (`Point { x, y }`, `(a, b)`) + nested bindings
|
||||
2. Match arm multi-stmt bodies (beyond single expr)
|
||||
3. LSP: wire hover types from real sema (replace lightweight index where possible)
|
||||
1. Match arm multi-stmt bodies (beyond single expr)
|
||||
2. Nested patterns deeper (`Some((a, b))`, `Point { x: (a, b) }`)
|
||||
3. LSP: wire hover types from real sema
|
||||
4. Generic type inference for `Iter_Map` without explicit `<T,U>`
|
||||
|
||||
Reference in New Issue
Block a user