Skip to content

Conversation

@rwstauner
Copy link
Contributor

@rwstauner rwstauner commented Oct 15, 2025

See the code comments:
The attribute accessors require RepeatedFields but the initializer requires an Array.

$ bin/console
tapioca(main):001> require "google/protobuf/well_known_types"
=> true

# initialize takes an Array
tapioca(main):003> fm = Google::Protobuf::FieldMask.new(paths: ["a", "b"])
=> <Google::Protobuf::FieldMask: paths: ["a", "b"]>
tapioca(main):004> fm.paths
=> ["a", "b"]
tapioca(main):005> fm.paths.class
=> Google::Protobuf::RepeatedField

# initialize with RepeatedField fails
tapioca(main):006> Google::Protobuf::FieldMask.new(paths: fm.paths)
(tapioca):6:in 'Google::Protobuf::AbstractMessage#initialize': Expected array as initializer value for repeated field 'paths' (given Google::Protobuf::RepeatedField). (ArgumentError)
        from (tapioca):6:in 'Class#new'
        from (tapioca):6:in '<top (required)>'
        from <internal:kernel>:168:in 'Kernel#loop'
        from bin/console:13:in '<main>'

# attr writer with Array fails
tapioca(main):010> fm.paths = ["a", "b"]
(tapioca):10:in 'Google::Protobuf::AbstractMessage#method_missing': Expected repeated field array (Google::Protobuf::TypeError)
        from (tapioca):10:in '<top (required)>'
        from <internal:kernel>:168:in 'Kernel#loop'
        from bin/console:13:in '<main>'

# attr writer takes RepeatedField
tapioca(main):014> fm.paths = Google::Protobuf::RepeatedField.new(:string, ["b", "c"])
=> ["b", "c"]
tapioca(main):015> fm.paths.class
=> Google::Protobuf::RepeatedField
tapioca(main):016> fm.paths
=> ["b", "c"]

We intend to report the inconsistency to Google, but even if they fix it it won't work for older versions.

Do we want the output of tapioca to match what protobuf does now?
Or would we want to leave this as is if Google were to fix protobuf?

@rwstauner rwstauner requested a review from a team as a code owner October 15, 2025 21:45
Copy link
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

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

Do we want the output of tapioca to match what protobuf does now?

I think this is better, we can always update later.

See the code comments:
The attribute accessors can use Enumerable but the initializer requires an Array.
@rwstauner rwstauner force-pushed the rwstauner/protobuf-repeated-field-init branch from 343c68d to 976d798 Compare October 20, 2025 23:48
@rwstauner rwstauner enabled auto-merge October 20, 2025 23:55
@rwstauner rwstauner merged commit db2a0ab into main Oct 21, 2025
16 checks passed
@rwstauner rwstauner deleted the rwstauner/protobuf-repeated-field-init branch October 21, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants