ruby-protobuf icon indicating copy to clipboard operation
ruby-protobuf copied to clipboard

Message.merge_from fails if target has an unset field of a custom type

Open aogail opened this issue 12 years ago • 0 comments

I am using ruby_protobuf version 0.4.11 and ruby 2.0.0p247.

Given a proto file:

message Foo {
}

message Bar {
    optional Foo f = 1;
}

Foo.merge_from() will fail if the target's f field is unset:

$ cat foo.rb
require './foo.pb'

b1 = Bar.new
b2 = Bar.new
b2.f = Foo.new
b1.merge_from(b2)

$ ruby foo.rb
/localhome/aogail/.rvm/gems/ruby-2.0.0-p247/gems/ruby_protobuf-0.4.11/lib/protobuf/message/field.rb:622:in `merge_value': undefined method `merge_from' for nil:NilClass (NoMethodError)
    from /localhome/aogail/.rvm/gems/ruby-2.0.0-p247/gems/ruby_protobuf-0.4.11/lib/protobuf/message/field.rb:104:in `merge'
    from /localhome/aogail/.rvm/gems/ruby-2.0.0-p247/gems/ruby_protobuf-0.4.11/lib/protobuf/message/message.rb:256:in `block in merge_from'
    from /localhome/aogail/.rvm/gems/ruby-2.0.0-p247/gems/ruby_protobuf-0.4.11/lib/protobuf/message/message.rb:256:in `each'
    from /localhome/aogail/.rvm/gems/ruby-2.0.0-p247/gems/ruby_protobuf-0.4.11/lib/protobuf/message/message.rb:256:in `merge_from'
    from foo.rb:6:in `<main>'

aogail avatar Jan 23 '14 21:01 aogail