From 1e6e235dca69555cd3734409dea7850522170456 Mon Sep 17 00:00:00 2001 From: Caspian Baska Date: Thu, 3 Nov 2022 02:14:55 +0800 Subject: [PATCH] Partial revert "Compiler: refactor and slightly optimize merging two types (#12436)" (#12709) This reverts part of commit bfc33dbda41ed4c3590d02bcdd781fcea5368fd3 The reverted part is 8d19346f5ca3394ed2e8f0367fe0d01734151d8f (Generalize the case of a non-union type merged with a union type) from #12436 --- src/compiler/crystal/semantic/type_merge.cr | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/crystal/semantic/type_merge.cr b/src/compiler/crystal/semantic/type_merge.cr index 027af4fcfa23..9b2fe4e236f5 100644 --- a/src/compiler/crystal/semantic/type_merge.cr +++ b/src/compiler/crystal/semantic/type_merge.cr @@ -46,12 +46,11 @@ module Crystal return second if first.no_return? return first if second.no_return? - # Check if a non-union type is part of a union type - if !first.is_a?(UnionType) && second.is_a?(UnionType) && second.union_types.includes?(first) + if first.nil_type? && second.is_a?(UnionType) && second.union_types.includes?(first) return second end - if !second.is_a?(UnionType) && first.is_a?(UnionType) && first.union_types.includes?(second) + if second.nil_type? && first.is_a?(UnionType) && first.union_types.includes?(second) return first end