Skip to content

Commit

Permalink
Fixed #169: responds_to? didn't work with generic classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Jul 24, 2014
1 parent ad28289 commit f567ba3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/compiler/codegen/responds_to_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,26 @@ describe "Codegen: responds_to?" do
it "codegens responds_to? with nilable gives false becuase other type 2" do
run("class Reference; def foo; end; end; (1 == 2 ? nil : Reference.new).responds_to?(:foo)").to_b.should be_true
end

it "codegends responds_to? with generic class (1)" do
run(%(
class Foo(T)
def foo
end
end
Foo(Int32).new.responds_to?(:foo)
)).to_b.should be_true
end

it "codegends responds_to? with generic class (2)" do
run(%(
class Foo(T)
def foo
end
end
Foo(Int32).new.responds_to?(:bar)
)).to_b.should be_false
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,10 @@ module Crystal
delegate :passed_by_value?, @generic_class
delegate :type_desc, @generic_class

def filter_by_responds_to(name)
@generic_class.filter_by_responds_to(name) ? self : nil
end

def class?
true
end
Expand Down

0 comments on commit f567ba3

Please sign in to comment.