diff --git a/proc.c b/proc.c index d0451244ce..cff8e9e7af 100644 --- a/proc.c +++ b/proc.c @@ -2684,7 +2684,7 @@ method_def_min_max_arity(const rb_method_definition_t *def, int *max) return 0; case OPTIMIZED_METHOD_TYPE_STRUCT_ASET: *max = 1; - return 0; + return 1; default: break; } diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index b0e6bae9e3..5a39ecc3aa 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -497,6 +497,20 @@ module TestStruct assert_equal(42, x.public_send("a")) end + def test_arity + klass = @Struct.new(:a) + assert_equal 0, klass.instance_method(:a).arity + assert_equal 1, klass.instance_method(:a=).arity + + klass.module_eval do + define_method(:b=, &klass.new.method(:a=).to_proc) + alias c= a= + end + + assert_equal 1, klass.instance_method(:b=).arity + assert_equal 1, klass.instance_method(:c=).arity + end + def test_parameters klass = @Struct.new(:a) assert_equal [], klass.instance_method(:a).parameters