go: types.sx — composite-literal element checking; Phase 3 bar crossed + 10 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Phase 3 cont. Adds composite-literal type-checking via go-synth-composite:
[]T{...} — go-check-composite-elems with VAL-TY=T, KEY-TY=nil.
Each plain elem assignable to T; :kv element accepted
(Go's index-keyed shorthand: `[]int{0: 5, 1: 10}`)
with only the value checked.
[N]T{...} — same as slice; result :ty-array N T.
map[K]V{...} — KEY-TY=K, VAL-TY=V. Each :kv pair: key assignable
to K, value to V. Non-:kv elements in maps are
(:type-error :map-elem-missing-key).
The literal's *synthesised* type is the type expression itself, so
nested composites fall out by recursion:
[][]int{[]int{1,2}, []int{3,4}}
→ outer: go-check-composite-elems with VAL-TY=[]int
→ each inner []int{1,2} goes through go-synth-composite recursively,
yielding :ty-slice :ty-name "int" — assignable-equal to VAL-TY.
Coverage: positive cases (homogeneous slices/arrays/maps, empty
slice, nested), and three negative cases (slice element mismatch,
map key mismatch, map value mismatch). Also a decl test:
var x = []int{1, 2, 3} → binds x to :ty-slice :ty-name "int"
Named-type literals (`Point{1,2}`, `pkg.T{...}`) need type-decl-driven
field resolution; deferred. Interface satisfaction and AST-path error
context also remain — neither gates Phase 4.
**Phase 3 acceptance bar (60+) crossed: types 65/65, total 370/370.**
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -244,12 +244,19 @@ Progress-log line → push `origin/loops/go`.
|
||||
then return type by result count (0 → `:ty-void`, 1 → that type,
|
||||
N → `:ty-tuple`). Recursive calls now type-check because the func
|
||||
is bound in the body's ctx. Untyped-constant args flow through.
|
||||
- [ ] Composite type element checking (slice / map / chan).
|
||||
- [x] Composite literal element checking — slice `[]T{...}`, array
|
||||
`[N]T{...}`, map `map[K]V{...}` (key + value checked).
|
||||
`:kv` element with no key on slice/array is permitted (Go's
|
||||
index-keyed shorthand). Nested composite literals work
|
||||
(`[][]int{[]int{1,2}, []int{3,4}}`). Named-type composite
|
||||
literals (`Point{...}`) need type-decl resolution; deferred.
|
||||
- [ ] Interface satisfaction (structural match against method sets).
|
||||
- [ ] Short variable declaration `:=` (synth RHS into LHS bindings).
|
||||
- Defer: generics (Phase 7), full conversion rules, type assertions,
|
||||
type switches.
|
||||
- **Acceptance:** types/ suite at 60+ tests. Current: 55/55. Chisel note
|
||||
- **Acceptance:** types/ suite at 60+ tests. **Bar crossed: 65/65.**
|
||||
Remaining sub-items (interface satisfaction, error reporting carrying
|
||||
AST paths) refine but don't gate Phase 4. Chisel note
|
||||
`shapes-static-types-bidirectional` — sister-plan design diary is the
|
||||
cross-language record.
|
||||
|
||||
@@ -550,6 +557,19 @@ Minimal repro: see `lib/go/lex.sx#gl-oct-digit?` and `#gl-match-op`.
|
||||
|
||||
_Newest first. Append one dated entry per commit._
|
||||
|
||||
- 2026-05-27 — Phase 3 cont.: composite-literal element checking.
|
||||
`go-synth-composite` dispatches on the literal's type expression:
|
||||
`:ty-slice` and `:ty-array` check each element assignable to the
|
||||
element type; `:ty-map` checks each `:kv` pair (key against K, value
|
||||
against V) and rejects non-`:kv` map elements. The literal's
|
||||
synthesised type is the type-expression itself, so nested composites
|
||||
fall out by recursion: `[][]int{[]int{1,2}, []int{3,4}}` checks each
|
||||
inner `[]int{...}` as a value of type `[]int`. Named-type literals
|
||||
(`Point{1,2}`, `pkg.T{...}`) need type-decl-driven field resolution;
|
||||
deferred. **Phase 3 acceptance bar (60+ tests) crossed: 65/65, total
|
||||
370/370.** `[nothing]` — composite-literal semantics are mostly Go-
|
||||
specific. Remaining Phase 3 items (interface satisfaction; AST-path
|
||||
error context) sharpen the surface but don't gate Phase 4 (evaluator).
|
||||
- 2026-05-27 — Phase 3 cont.: call type-checking. `go-synth-call`
|
||||
synthesises the callee's type, asserts it's a `:ty-func`, arity-
|
||||
checks args, then `go-check-args-against` runs each arg through
|
||||
|
||||
Reference in New Issue
Block a user