diff --git a/spec/compiler/type_inference/module_spec.cr b/spec/compiler/type_inference/module_spec.cr
index 6d70a3b60983d664e283a2a5f471e4029d39df7f..d7210f64c4da921674df9693d6faf8478034e413 100755
--- a/spec/compiler/type_inference/module_spec.cr
+++ b/spec/compiler/type_inference/module_spec.cr
@@ -645,4 +645,24 @@ describe "Type inference: module" do
       Baz(Int32).new.foo
       )) { int32.metaclass }
   end
+
+  it "types union of module and class that includes it" do
+    assert_type(%(
+      module Moo
+        def self.foo
+          1
+        end
+      end
+
+      class Bar
+        include Moo
+
+        def self.foo
+          2
+        end
+      end
+
+      Bar || Moo
+      )) { union_of(types["Bar"].metaclass, types["Moo"].metaclass) }
+  end
 end
diff --git a/src/compiler/crystal/semantic/type_merge.cr b/src/compiler/crystal/semantic/type_merge.cr
index 41991ee1138a1a0aaad32b56f11496a86ddced90..d0b3006ac23fae238fa3ee4f6075cb347b99f516 100644
--- a/src/compiler/crystal/semantic/type_merge.cr
+++ b/src/compiler/crystal/semantic/type_merge.cr
@@ -215,8 +215,12 @@ module Crystal
 
   class MetaclassType
     def common_ancestor(other : MetaclassType)
-      common = instance_type.common_ancestor(other.instance_type)
-      common.try &.metaclass
+      if instance_type.module? || other.instance_type.module?
+        nil
+      else
+        common = instance_type.common_ancestor(other.instance_type)
+        common.try &.metaclass
+      end
     end
   end