Skip to content

Commit

Permalink
Fix TypeError: wrong argument type NilClass (must respond to :each)
Browse files Browse the repository at this point in the history
This error occurred when I tested `typeprof` on `test-unit`.
https://github.com/test-unit/test-unit/blob/24fb08fe31835b0d9ade80fb2f51554e55d1a74a/lib/test/unit/attribute.rb#L4

Although `superclass_type_args` may be nil, it was passed to `Array#zip` and raised a TypeError.
https://github.com/ruby/typeprof/blob/c440ce91d8903c9e284f911b13ca49320f6a1fb7/lib/typeprof/core/env.rb#L115

I changed it to if superclass_type_args is nil, use an empty array instead.
  • Loading branch information
alpaca-tc committed Jul 24, 2024
1 parent c440ce9 commit 025caef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/typeprof/core/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_superclass_type(ty, changes, base_ty_env)
if singleton
Type::Singleton.new(self, super_mod)
else
get_instance_type(super_mod, ty.mod.superclass_type_args, changes, base_ty_env, ty)
get_instance_type(super_mod, ty.mod.superclass_type_args || [], changes, base_ty_env, ty)
end
end

Expand Down
12 changes: 12 additions & 0 deletions scenario/misc/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ def foo: -> :int
class D2 < C
def foo: -> :str
end

## update
class StringifyKeyHash < Hash
def [](key)
super(key.to_s)
end
end

## assert
class StringifyKeyHash < Hash
def []: (untyped) -> untyped
end

0 comments on commit 025caef

Please sign in to comment.