|
@@ -217,6 +217,9 @@ public class RubyMessage extends RubyObject {
|
|
RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass);
|
|
RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass);
|
|
IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]);
|
|
IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]);
|
|
if (oneofDescriptor.isNil()) {
|
|
if (oneofDescriptor.isNil()) {
|
|
|
|
+ if (!hasField(args[0])) {
|
|
|
|
+ throw context.runtime.newNoMethodError("undefined method `" + args[0].toString() + "' for " + metaClass.toString(), args[0].asJavaString(), metaClass);
|
|
|
|
+ }
|
|
return index(context, args[0]);
|
|
return index(context, args[0]);
|
|
}
|
|
}
|
|
RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor;
|
|
RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor;
|
|
@@ -233,6 +236,10 @@ public class RubyMessage extends RubyObject {
|
|
if (field.end_with_p(context, equalSign).isTrue()) {
|
|
if (field.end_with_p(context, equalSign).isTrue()) {
|
|
field.chomp_bang(context, equalSign);
|
|
field.chomp_bang(context, equalSign);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (!hasField(field)) {
|
|
|
|
+ throw context.runtime.newNoMethodError("undefined method `" + args[0].asJavaString() + "' for " + metaClass.toString(), args[0].asJavaString(), metaClass);
|
|
|
|
+ }
|
|
return indexSet(context, field, args[1]);
|
|
return indexSet(context, field, args[1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -435,6 +442,11 @@ public class RubyMessage extends RubyObject {
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private boolean hasField(IRubyObject fieldName) {
|
|
|
|
+ String nameStr = fieldName.asJavaString();
|
|
|
|
+ return this.descriptor.findFieldByName(Utils.escapeIdentifier(nameStr)) != null;
|
|
|
|
+ }
|
|
|
|
+
|
|
private void checkRepeatedFieldType(ThreadContext context, IRubyObject value,
|
|
private void checkRepeatedFieldType(ThreadContext context, IRubyObject value,
|
|
Descriptors.FieldDescriptor fieldDescriptor) {
|
|
Descriptors.FieldDescriptor fieldDescriptor) {
|
|
Ruby runtime = context.runtime;
|
|
Ruby runtime = context.runtime;
|