Add reflect.Type.ConvertibleTo()#5422
Conversation
ee98b78 to
cf6469f
Compare
|
There's a bunch more conversions that are still stubbed, but this one was commented out and easy enough to handle. |
This PR removes convert_test.go which was a minimal version of this test.
99092f2 to
552e9b0
Compare
|
Ready for review! |
There was a problem hiding this comment.
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.ConvertibleToand wire(reflect.Type).ConvertibleTothrough it. - Flesh out
convertOp(complex, pointer, string↔runes) and addcvtComplex/cvtDirect/makeComplexplus realcvtIntString/cvtUintString/cvtStringRunes/cvtRunesStringimplementations. - Re-enable large portions of upstream
convertTests/TestConvert, exposeIsRO/MakeRO, deleteconvert_test.go, rename oldTestConvert→TestConvertBasic, and adjustencodeUTF8signature.
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.
6eab4c5 to
ec6264b
Compare
No description provided.