Skip to content

Add reflect.Type.ConvertibleTo()#5422

Open
dgryski wants to merge 9 commits into
tinygo-org:devfrom
dgryski:dgryski/convertible-to
Open

Add reflect.Type.ConvertibleTo()#5422
dgryski wants to merge 9 commits into
tinygo-org:devfrom
dgryski:dgryski/convertible-to

Conversation

@dgryski
Copy link
Copy Markdown
Member

@dgryski dgryski commented May 25, 2026

No description provided.

@dgryski dgryski force-pushed the dgryski/convertible-to branch from ee98b78 to cf6469f Compare May 25, 2026 19:08
@dgryski
Copy link
Copy Markdown
Member Author

dgryski commented May 25, 2026

There's a bunch more conversions that are still stubbed, but this one was commented out and easy enough to handle.

@dgryski dgryski force-pushed the dgryski/convertible-to branch from 99092f2 to 552e9b0 Compare May 29, 2026 21:06
@dgryski
Copy link
Copy Markdown
Member Author

dgryski commented May 29, 2026

Ready for review!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements reflect.Type.ConvertibleTo (previously a panic stub) by adding a type-level ConvertibleTo method on internal/reflectlite.RawType, and fills in the remaining reflect.Value.Convert machinery (complex, pointer, string↔runes, int/uint→string) needed for the conversion tests. The PR also re-enables a large portion of the upstream convertTests table in reflect/all_test.go, deletes the narrower convert_test.go, exposes test-only IsRO/MakeRO helpers on reflectlite.Value, renames the basic conversion test to TestConvertBasic to avoid colliding with the re-enabled TestConvert, and tweaks runtime.encodeUTF8 to take a rune and widen to uint32 internally.

Changes:

  • Implement RawType.ConvertibleTo and wire (reflect.Type).ConvertibleTo through it.
  • Flesh out convertOp (complex, pointer, string↔runes) and add cvtComplex/cvtDirect/makeComplex plus real cvtIntString/cvtUintString/cvtStringRunes/cvtRunesString implementations.
  • Re-enable large portions of upstream convertTests/TestConvert, expose IsRO/MakeRO, delete convert_test.go, rename old TestConvertTestConvertBasic, and adjust encodeUTF8 signature.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/reflect/type.go Replace ConvertibleTo panic stub with delegation to RawType.ConvertibleTo.
src/internal/reflectlite/type.go New RawType.ConvertibleTo covering numeric, slice/string, pointer, identical-underlying, and empty-interface cases (struct/chan TODO).
src/internal/reflectlite/value.go Add complex/pointer conversion paths, real cvt* string helpers, makeComplex/cvtDirect, and expose IsRO/MakeRO.
src/reflect/all_test.go Re-enable upstream convertTests and TestConvert, add IsRO/MakeRO helpers; keep struct-tag/channel/interface and slice-panic tests commented out.
src/reflect/convert_test.go Deleted; numeric coverage subsumed by all_test.go.
src/reflect/value_test.go Rename existing TestConvert to TestConvertBasic to avoid name collision.
src/runtime/string.go encodeUTF8 now takes rune and converts to uint32 internally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal/reflectlite/value.go
Comment thread src/internal/reflectlite/value.go
Comment thread src/internal/reflectlite/type.go Outdated
Comment thread src/internal/reflectlite/value.go Outdated
Comment thread src/internal/reflectlite/type.go Outdated
@dgryski dgryski force-pushed the dgryski/convertible-to branch from 6eab4c5 to ec6264b Compare May 30, 2026 08:42
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