diff --git a/spec/compiler/semantic/module_spec.cr b/spec/compiler/semantic/module_spec.cr index 48b95c757506..e4413f3c01b9 100644 --- a/spec/compiler/semantic/module_spec.cr +++ b/spec/compiler/semantic/module_spec.cr @@ -1259,4 +1259,26 @@ describe "Semantic: module" do ), "can't declare instance variables in Bar:Class" end + + it "can't pass module class to virtual metaclass (#6113)" do + assert_error %( + module Moo + end + + class Foo + end + + class Bar < Foo + include Moo + end + + class Gen(T) + def self.foo(x : T) + end + end + + Gen(Foo.class).foo(Moo) + ), + "no overload matches" + end end diff --git a/src/compiler/crystal/semantic/restrictions.cr b/src/compiler/crystal/semantic/restrictions.cr index 48f63e0e4037..0bcbb5168ae8 100644 --- a/src/compiler/crystal/semantic/restrictions.cr +++ b/src/compiler/crystal/semantic/restrictions.cr @@ -953,6 +953,9 @@ module Crystal end def restrict(other : VirtualMetaclassType, context) + # A module class can't be restricted into a class + return nil if instance_type.module? + restricted = instance_type.restrict(other.instance_type.base_type, context) restricted ? self : nil end