Skip to content

Commit 56ec1e7

Browse files
authored
Merge pull request #15448 from rudkx/make-type-join-more-resilient
Add support for Builtin types to Type::join.
2 parents 28f85e4 + 1ad5a13 commit 56ec1e7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/AST/TypeJoinMeet.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ struct TypeJoin : CanTypeVisitor<TypeJoin, CanType> {
7373
CanType visitProtocolCompositionType(CanType second);
7474
CanType visitLValueType(CanType second);
7575
CanType visitInOutType(CanType second);
76+
CanType visitBuiltinType(CanType second);
7677

7778
CanType visitType(CanType second) {
78-
llvm_unreachable("Unimplemented type visitor!");
79+
return Unimplemented;
7980
}
8081

8182
public:
@@ -368,6 +369,13 @@ CanType TypeJoin::visitLValueType(CanType second) { return Unimplemented; }
368369

369370
CanType TypeJoin::visitInOutType(CanType second) { return Unimplemented; }
370371

372+
CanType TypeJoin::visitBuiltinType(CanType second) {
373+
assert(First != second);
374+
375+
// BuiltinType with any non-equal type results in Any.
376+
return TheAnyType;
377+
}
378+
371379
} // namespace
372380

373381
Optional<Type> Type::join(Type first, Type second) {

test/Sema/type_join.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ expectEqualType(Builtin.type_join(D?.self, Any.self), Any?.self)
3434
expectEqualType(Builtin.type_join(Any?.self, Any.self), Any?.self)
3535
expectEqualType(Builtin.type_join(Any.self, Any?.self), Any?.self)
3636

37+
expectEqualType(Builtin.type_join(Builtin.Int1.self, Builtin.Int1.self), Builtin.Int1.self)
38+
expectEqualType(Builtin.type_join(Builtin.Int32.self, Builtin.Int1.self), Any.self)
39+
expectEqualType(Builtin.type_join(Builtin.Int1.self, Builtin.Int32.self), Any.self)
40+
3741
func joinFunctions(
3842
_ escaping: @escaping () -> (),
3943
_ nonescaping: () -> ()

0 commit comments

Comments
 (0)