Fix autoboxing of wrapperspb types #100
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Autoboxing of wrapperspb types was only partially working, allowing
msg.f_StringValue = "something"
to typecheck (typechecking was done byvalueFromStarlark
which does the autoboxing) but the assignment was actually assigning"something"
a string into the internalfields
map. Then when access happens,msg.f_StringValue.value
fails becausemsg.f_StringValue == "something"
and does not have.value
This PR removes
maybeConvertToWrapper
fromvalueFromStarlark
so typechecking fails if the conversion has not been explicitly done before assignment. The conversion is moved earlier intoprotoMessage.SetField
where thelist/dict
conversions are done.As an extra fun, there was existing support for converting
["s1", "s2"]
into[StringValue{value: s1}, StringValue{value: s2}]
which breaks the list assignment semantics. In this case the assignment mutates like map do for None, though it could alternatively copy if we want.Longer term, I'd really like to get rid of this autoboxing behavior, its convenient but adds a lot of complexity
Tests
I added tests to
protomodule_message_test