Skip to content

Commit

Permalink
Compiler: fix type check not considering virtual types (#10304)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and bcardiff committed Jan 29, 2021
1 parent 1a65b22 commit 3d55277
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions spec/compiler/codegen/is_a_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,20 @@ describe "Codegen: is_a?" do
Class.is_a?(Class.class.class)
").to_b.should be_true
end

it "passes is_a? with generic module type on virtual type (#10302)" do
run(%(
module Mod(T)
end
abstract struct Sup
include Mod(Sup)
end
struct Sub < Sup
end
Sub.new.is_a?(Mod(Sup))
)).to_b.should be_true
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/restrictions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ module Crystal
other_type_var = other.type_vars[name]
if type_var.is_a?(Var) && other_type_var.is_a?(Var)
restricted = if strict
type_var.type == other_type_var.type
type_var.type.devirtualize == other_type_var.type.devirtualize
else
type_var.type.implements?(other_type_var.type)
end
Expand Down

0 comments on commit 3d55277

Please sign in to comment.