go: types.sx — declaration checking (var/const/type + :=) + 12 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s

Phase 3 cont. Adds go-check-decl which dispatches on AST shape and
returns either the extended context or a :type-error:

  :var-decl     (:field NAMES TYPE-or-nil) EXPRS-or-nil
  :const-decl   (same shape; same logic in v0 — mutability later)
  :short-decl   LHS-LIST EXPRS         (lhs is a list of :var nodes)
  :type-decl    NAME TYPE              (type alias)

New helpers:

  go-default-type      — untyped-int → int, untyped-float → float64,
                         etc. Used when inferring var x = EXPR.
  go-check-exprs-against — every expr assignable to the declared type.
  go-bind-names-to-synth  — pair names with default-typed synth of
                            corresponding exprs; extends ctx.

The canonical Go pitfall flows through end-to-end now:

  (go-check-decl ctx (go-parse "var x float64 = 42 / 7"))
  →  ctx + (x → float64)

Because: 42/7 synthesises to ty-untyped-int (binop result of two
untyped operands), then go-check-exprs-against uses go-type-assignable?
to check ty-untyped-int → ty-name "float64" — :ok via the
untyped-int-to-any-numeric assignability rule. The 6 (integer) result
gets float-converted on assignment, never floated mid-computation.

types 40/40, total 345/345.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:49:27 +00:00
parent 86ddaf255c
commit 5e27a7f0c9
5 changed files with 202 additions and 8 deletions

View File

@@ -228,8 +228,12 @@ Progress-log line → push `origin/loops/go`.
successfully against `float64`. Untyped int + untyped float
unifies to untyped float. Typed-var + untyped-int propagates the
var's type. Comparison/logical ops produce `bool`.
- [ ] Var/const declaration checking (`var x T = expr`, `var x = expr`,
`const Pi = 3.14`).
- [x] Var/const declaration checking (`var x T = expr`, `var x = expr`,
`var x T`, `const Pi = 3.14`, `type T int`, `var x, y int`, plus
short-decl `x := 5` and `a, b := 1, 2`). `go-check-decl` returns
the extended context or a `:type-error`. Untyped synthesized types
get their default-type (`untyped-int → int`, `untyped-float →
float64`, etc.) when bound in inferred-type decls.
- [ ] Function declaration: extend ctx with params via `:field` group,
check body, verify return-list types match signature.
- [ ] Call type-checking (synth callee, check args against param types,
@@ -239,7 +243,7 @@ Progress-log line → push `origin/loops/go`.
- [ ] 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: 28/28. Chisel note
- **Acceptance:** types/ suite at 60+ tests. Current: 40/40. Chisel note
`shapes-static-types-bidirectional` — sister-plan design diary is the
cross-language record.
@@ -540,6 +544,18 @@ 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.: declaration checking — `var`/`const`/`type`
+ short-decl `:=`. `go-check-decl` returns the extended context (or a
`:type-error`). New helpers: `go-default-type` (untyped-int → int,
untyped-float → float64, etc.), `go-check-exprs-against`,
`go-bind-names-to-synth`. Annotated decls check each init expression
is assignable to the declared type; inferred decls bind names to the
default-typed synthesis of the init. **`var x float64 = 42 / 7` and
`const C int = 42` both bind x to float64 / C to int correctly via
the assignability relation from the previous commit.** +12 tests,
types 40/40, total 345/345. `[nothing]` — the kit-relevant insights
(synth/check + assignable predicate) already in the diary; this is
pure Go-side composition on top.
- 2026-05-27 — Phase 3 cont.: literal synth + binop synth + assignability.
Heuristic `go-classify-literal-string` decodes the parser's untagged
literal values back into `:int`/`:float`/`:imag`/`:string` kinds