Skip to content

Commit

Permalink
Compiler: fix is_a? from generic class against generic class instance…
Browse files Browse the repository at this point in the history
… type (#12312)
  • Loading branch information
asterite authored Jul 24, 2022
1 parent ee8fca2 commit d939d6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/compiler/codegen/is_a_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,21 @@ describe "Codegen: is_a?" do
end
)).to_i.should eq(2)
end

it "does is_a? for generic type against generic class instance type (#12304)" do
run(%(
require "prelude"
class A
end
class B(T) < A
end
a = B(Int32).new.as(A)
b = a.as(B)
b.is_a?(B(Int32))
)).to_b.should be_true
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/semantic/type_intersect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ module Crystal
common_descendent_instance_and_generic(type1, type2)
end

def self.common_descendent(type1 : GenericClassType, type2 : GenericClassInstanceType)
common_descendent(type2, type1)
end

def self.common_descendent(type1 : GenericInstanceType, type2 : GenericInstanceType)
common_descendent_generic_instances(type1, type2) ||
common_descendent_base(type1, type2)
Expand Down

0 comments on commit d939d6f

Please sign in to comment.