Skip to content

Add support for Builtin types to Type::join. #15448

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

Merged
merged 1 commit into from
Mar 23, 2018
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
10 changes: 9 additions & 1 deletion lib/AST/TypeJoinMeet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ struct TypeJoin : CanTypeVisitor<TypeJoin, CanType> {
CanType visitProtocolCompositionType(CanType second);
CanType visitLValueType(CanType second);
CanType visitInOutType(CanType second);
CanType visitBuiltinType(CanType second);

CanType visitType(CanType second) {
llvm_unreachable("Unimplemented type visitor!");
return Unimplemented;
}

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

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

CanType TypeJoin::visitBuiltinType(CanType second) {
assert(First != second);

// BuiltinType with any non-equal type results in Any.
return TheAnyType;
}

} // namespace

Optional<Type> Type::join(Type first, Type second) {
Expand Down
4 changes: 4 additions & 0 deletions test/Sema/type_join.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ expectEqualType(Builtin.type_join(D?.self, Any.self), Any?.self)
expectEqualType(Builtin.type_join(Any?.self, Any.self), Any?.self)
expectEqualType(Builtin.type_join(Any.self, Any?.self), Any?.self)

expectEqualType(Builtin.type_join(Builtin.Int1.self, Builtin.Int1.self), Builtin.Int1.self)
expectEqualType(Builtin.type_join(Builtin.Int32.self, Builtin.Int1.self), Any.self)
expectEqualType(Builtin.type_join(Builtin.Int1.self, Builtin.Int32.self), Any.self)

func joinFunctions(
_ escaping: @escaping () -> (),
_ nonescaping: () -> ()
Expand Down