Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't merge NamedTuple metaclasses through instance types #10501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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