Skip to content

Commit

Permalink
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/compiler/semantic/restrictions_spec.cr
Original file line number Diff line number Diff line change
@@ -381,4 +381,20 @@ describe "Restrictions" do
Foo.new(1)
)) { generic_class "Foo", int32 }
end

it "restricts virtual metaclass type against metaclass (#3438)" do
assert_type(%(
class Parent
end
class Child < Parent
end
def foo(x : Parent.class)
x
end
foo(Parent || Child)
)) { types["Parent"].metaclass.virtual_type! }
end
end
6 changes: 6 additions & 0 deletions src/compiler/crystal/semantic/restrictions.cr
Original file line number Diff line number Diff line change
@@ -815,6 +815,12 @@ module Crystal
end
end

class VirtualMetaclassType
def restrict(other : Metaclass, context)
instance_type.restrict(other.name, context).try &.metaclass
end
end

class NonGenericModuleType
def restrict(other, context)
super || including_types.try(&.restrict(other, context))

0 comments on commit 203da3a

Please sign in to comment.