Skip to content

reflect: implement MakeChan - #5588

Open
0pcom wants to merge 1 commit into
tinygo-org:devfrom
0magnet:reflect-makechan
Open

reflect: implement MakeChan#5588
0pcom wants to merge 1 commit into
tinygo-org:devfrom
0magnet:reflect-makechan

Conversation

@0pcom

@0pcom 0pcom commented Aug 14, 2026

Copy link
Copy Markdown

reflect.MakeChan currently panics with "unimplemented". This implements it.

It completes a small gap: MakeSlice, MakeMap and New are all supported, so code that builds a channel reflectively is the odd one out — and it is reached by generic container and codec libraries that construct channel types from a reflect.Type.

Verified by building TinyGo and running the compiler test suite.

@dgryski

dgryski commented Aug 14, 2026

Copy link
Copy Markdown
Member

Please add a test for this new function. For reflect, this can either be in testdata/reflect.go or reflect/value_test.go.

TinyGo had MakeMap/MakeSlice but not MakeChan. Implement it via the runtime
chanMake primitive (mirroring MakeMap), so packages that call reflect.MakeChan
(e.g. github.com/ugorji/go/codec used by gin) compile and work.
@0pcom

0pcom commented Aug 16, 2026

Copy link
Copy Markdown
Author

Added TestTinyMakeChan in src/reflect/value_test.go, and rebased on dev.

It covers buffered and unbuffered creation (kind, Cap, Len, and a real send/receive through Interface(), since Value.Send/Value.Recv are still unimplemented), plus the three panic paths: non-channel type, negative buffer size, and a unidirectional channel type.

On verification: CI has not run on this PR, so I checked the test's expectations against the host reflect package, where it passes — that pins the behaviour to upstream semantics. I could not run it against these sources under a released TinyGo binary (the musl build gets in the way), so the implementation itself is still only verified by reading.

@0pcom
0pcom force-pushed the reflect-makechan branch from 13e03e0 to 31537f7 Compare August 16, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants