Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler: fix is_a? from generic class against generic class instance type #12312

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Compiler: fix is_a? from generic class against generic class instance…
… type
Ary Borenszweig committed Jul 24, 2022
commit 0c50b851a8d5bccb99604658c5a0961f8d8530b0
17 changes: 17 additions & 0 deletions spec/compiler/codegen/is_a_spec.cr
Original file line number Diff line number Diff line change
@@ -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
@@ -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)