go: Phase 7 foundation — generics syntax through parser/typer/eval [shapes-static-types-bidirectional]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
gp-parse-type-params consumes the optional [NAMES CONSTRAINT, ...] clause after a func name. AST stays backward-compatible: 5-slot func-decl when no [...] is present, 6-slot when it is. Typer binds each type-param name as (:ty-param NAME CONSTRAINT) so body's (:ty-name "T") references resolve. Eval is type-erasing — ignores type info, dispatches by name + arity. 10 new tests: parse (3), types (5), eval (2). Total 527/527. Shape: the field binding-group from the canonical kit now feeds 6 consumers (struct fields, var-decls, const-decls, params, receivers, type-params). Confirms it as a TRUE cross-deliverable shape — sister-plan diary documents the 5 roles binding-groups take and why the kit should expose ONE parser + pluggable validators. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -793,6 +793,38 @@
|
||||
(list
|
||||
(ast-app (ast-var "+") (list (ast-var "x") (ast-var "y")))))))))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: generic identity func with one type param [T any]"
|
||||
(go-parse "func Id[T any](x T) T { return x }")
|
||||
(list
|
||||
:func-decl "Id"
|
||||
(list (list :field (list "x") (list :ty-name "T")))
|
||||
(list (list :ty-name "T"))
|
||||
(list :block (list (list :return (list (list :var "x")))))
|
||||
(list (list :field (list "T") (list :ty-name "any")))))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: generic with two type params [T, U any]"
|
||||
(go-parse "func Map[T, U any](x T) U { return x }")
|
||||
(list
|
||||
:func-decl "Map"
|
||||
(list (list :field (list "x") (list :ty-name "T")))
|
||||
(list (list :ty-name "U"))
|
||||
(list :block (list (list :return (list (list :var "x")))))
|
||||
(list (list :field (list "T" "U") (list :ty-name "any")))))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: generic with multi-group type params"
|
||||
(go-parse "func F[T any, U comparable]() {}")
|
||||
(list
|
||||
:func-decl "F"
|
||||
(list)
|
||||
(list)
|
||||
(list :block (list))
|
||||
(list
|
||||
(list :field (list "T") (list :ty-name "any"))
|
||||
(list :field (list "U") (list :ty-name "comparable")))))
|
||||
|
||||
(go-parse-test
|
||||
"fdecl: func with multi-group params"
|
||||
(go-parse "func mix(x int, y string) {}")
|
||||
@@ -830,8 +862,8 @@
|
||||
"String"
|
||||
(list)
|
||||
(list (list :ty-name "string"))
|
||||
(list :block
|
||||
(list (list :return (list (list :select (ast-var "p") "x")))))))
|
||||
(list
|
||||
:block (list (list :return (list (list :select (ast-var "p") "x")))))))
|
||||
|
||||
(go-parse-test
|
||||
"mdecl: method on value receiver"
|
||||
@@ -846,7 +878,10 @@
|
||||
(go-parse-test
|
||||
"fdecl: body with return"
|
||||
(go-parse "func ret() { return 42 }")
|
||||
(list :func-decl "ret" (list) (list)
|
||||
(list
|
||||
:func-decl "ret"
|
||||
(list)
|
||||
(list)
|
||||
(list :block (list (list :return (list (ast-literal "42")))))))
|
||||
|
||||
(go-parse-test
|
||||
|
||||
Reference in New Issue
Block a user