go: parse.sx — interface type expressions + 8 tests; type expressions DONE [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Adds Go interface type expressions:
  interface {}                              →  empty
  interface { Close() }                     →  no-param method
  interface { String() string }             →  with single return
  interface { Read([]byte) (int, error) }   →  multi-return method
  interface { Stringer }                    →  embedded named iface
  interface { io.Reader }                   →  qualified embedded
  interface { io.Reader; Close() error }    →  mixed

gp-parse-interface-elems walks elements tolerating ASI semis. Each
element is either:
  (list :method NAME PARAMS RESULTS)
  (list :embed TYPE)

Method params/results reuse gp-parse-func-type-params/results — the
shape is identical to a free-standing func type. Go 1.18+ type sets
(interface { ~int | ~float64 }) are deferred until the generics
sub-deliverable.

With this, the full Phase 2 **type expressions** sub-deliverable is
complete (pending only field tags, struct/iface embeds details,
variadic, named func params, generics — all flagged later).

parse 106/106, total 235/235.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 08:16:24 +00:00
parent a94ffa0feb
commit 48379e04bc
5 changed files with 153 additions and 11 deletions

View File

@@ -577,6 +577,79 @@
(list
:ty-struct (list (list :field (list "x") (list :ty-name "int")))))))))
(go-parse-test
"ty: interface {} (empty)"
(go-parse "v.(interface {})")
(list :assert (ast-var "v") (list :ty-interface (list))))
(go-parse-test
"ty: interface { Close() } (single method, no params, no return)"
(go-parse "v.(interface { Close() })")
(list
:assert (ast-var "v")
(list :ty-interface (list (list :method "Close" (list) (list))))))
(go-parse-test
"ty: interface { String() string } (single return)"
(go-parse "v.(interface { String() string })")
(list
:assert (ast-var "v")
(list
:ty-interface (list (list :method "String" (list) (list (list :ty-name "string")))))))
(go-parse-test
"ty: interface { Read([]byte) (int, error) } (multi return)"
(go-parse "v.(interface { Read([]byte) (int, error) })")
(list
:assert (ast-var "v")
(list
:ty-interface (list
(list
:method "Read"
(list (list :ty-slice (list :ty-name "byte")))
(list (list :ty-name "int") (list :ty-name "error")))))))
(go-parse-test
"ty: interface { Stringer } (embedded interface)"
(go-parse "v.(interface { Stringer })")
(list
:assert (ast-var "v")
(list :ty-interface (list (list :embed (list :ty-name "Stringer"))))))
(go-parse-test
"ty: interface { io.Reader } (qualified embedded)"
(go-parse "v.(interface { io.Reader })")
(list
:assert (ast-var "v")
(list :ty-interface (list (list :embed (list :ty-sel "io" "Reader"))))))
(go-parse-test
"ty: interface with embed + methods (io.ReadWriter style)"
(go-parse "v.(interface { io.Reader; Close() error })")
(list
:assert (ast-var "v")
(list
:ty-interface (list
(list :embed (list :ty-sel "io" "Reader"))
(list :method "Close" (list) (list (list :ty-name "error")))))))
(go-parse-test
"ty: interface with multiple methods"
(go-parse "v.(interface { Read([]byte) int; Write([]byte) int; Close() })")
(list
:assert (ast-var "v")
(list
:ty-interface (list
(list
:method "Read"
(list (list :ty-slice (list :ty-name "byte")))
(list (list :ty-name "int")))
(list
:method "Write"
(list (list :ty-slice (list :ty-name "byte")))
(list (list :ty-name "int")))
(list :method "Close" (list) (list))))))
(go-parse-test "non-primary: '+'" (go-parse "+") nil)
(go-parse-test "non-primary: empty" (go-parse "") nil)