Skip to content

reflect: add TypeAssert - #5160

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
jakebailey:reflect-type-assert
Jan 8, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
jakebailey:reflect-type-assert

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This function was missing, leading to:

# github.com/go-json-experiment/json
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_funcs.go:181:20: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_funcs.go:227:20: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_funcs.go:275:20: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_funcs.go:314:20: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_inlined.go:54:19: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_inlined.go:177:19: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:133:28: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:159:27: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:182:28: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:216:28: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:256:30: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:283:30: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_methods.go:310:30: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_time.go:60:22: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_time.go:87:21: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_time.go:131:22: undefined: reflect.TypeAssert
../../go/pkg/mod/github.com/go-json-experiment/json@v0.0.0-20251027170946-4849db3c2f7e/arshal_time.go:157:21: undefined: reflect.TypeAssert

I ported the (theoreticlaly faster) reflectlite version of this, rather than just doing v.Interface().(T), and copied the tests. I am not sure what's typical for this.

@jakebailey

Copy link
Copy Markdown
Member Author

Hm, make test doesn't complain about this; I'll have to figure out how to run these tests myself.

I can always flip it to the less optimal version if I don't figure out the deal here; perhaps the pointer arithmetic done in big Go does not apply to tinygo

@dgryski dgryski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just needs to skip the panic test on wasi.

Comment thread src/reflect/value_test.go
Comment thread src/reflect/value_test.go
@jakebailey
jakebailey force-pushed the reflect-type-assert branch from 0a69cba to 77bb092 Compare January 8, 2026 04:21
Comment thread src/reflect/value_test.go Outdated
@jakebailey
jakebailey force-pushed the reflect-type-assert branch from 77bb092 to 67b8d02 Compare January 8, 2026 20:04

@dgryski dgryski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jakebailey

Copy link
Copy Markdown
Member Author
--- FAIL: TestTypeAssertPanic (0.00s)
    recover not supported
    SkipNow is incomplete, requires runtime.Goexit()

I guess I should just log and return instead.

@jakebailey
jakebailey force-pushed the reflect-type-assert branch from 67b8d02 to 9290ab5 Compare January 8, 2026 20:37

@dgryski dgryski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@deadprogram

Copy link
Copy Markdown
Member

Thanks for the addition @jakebailey and to @dgryski for doing the reviewing. Now merging.

@deadprogram
deadprogram merged commit 068d7c1 into tinygo-org:dev Jan 8, 2026
19 checks passed
@jakebailey
jakebailey deleted the reflect-type-assert branch April 14, 2026 20:36
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.

3 participants