Skip to content

Commit

Permalink
Don't merge NamedTuple metaclasses through instance types (#10501)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Mar 15, 2021
1 parent aa91eb3 commit 2698c43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/compiler/semantic/named_tuple_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,15 @@ describe "Semantic: named tuples" do
call("")
)) { int32 }
end

it "doesn't unify named tuple metaclasses (#5384)" do
assert_type(%(
NamedTuple(a: Int32) || NamedTuple(a: String)
)) {
union_of(
named_tuple_of({"a": int32}).metaclass,
named_tuple_of({"a": string}).metaclass,
)
}
end
end
3 changes: 3 additions & 0 deletions src/compiler/crystal/semantic/type_merge.cr
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ module Crystal
# Tuple instances might be unified, but never tuple metaclasses
return nil if instance_type.is_a?(TupleInstanceType) || other.instance_type.is_a?(TupleInstanceType)

# NamedTuple instances might be unified, but never named tuple metaclasses
return nil if instance_type.is_a?(NamedTupleInstanceType) || other.instance_type.is_a?(NamedTupleInstanceType)

common = instance_type.common_ancestor(other.instance_type)
common.try &.metaclass
end
Expand Down

0 comments on commit 2698c43

Please sign in to comment.