Skip to content

Commit 30eb09f

Browse files
committed
[Type Resolution] Instead of importing id<> types as constraints,
allow imported existential typealiases to be used in protocol constraint context.
1 parent 791648b commit 30eb09f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,16 +2796,6 @@ namespace {
27962796
SourceLoc(), Name,
27972797
Loc,
27982798
/*genericparams*/nullptr, DC);
2799-
2800-
// Unwrap an explicit ExistentialType around the underlying type so that
2801-
// the typealias can be used in a generic constraint context.
2802-
//
2803-
// FIXME: We might want to push this down further into importType(), and
2804-
// once ExistentialType becomes mandatory in the future we want to wrap
2805-
// references to imported typealiases in Sema's resolveType() as well.
2806-
if (auto *existentialType = SwiftType->getAs<ExistentialType>())
2807-
SwiftType = existentialType->getConstraintType();
2808-
28092799
Result->setUnderlyingType(SwiftType);
28102800

28112801
// Make Objective-C's 'id' unavailable.

lib/Sema/TypeCheckType.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,17 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
34993499
return ExistentialType::get(result);
35003500
}
35013501

3502+
if (!options.isConstraintImplicitExistential()) {
3503+
// Imported existential typealiases, e.g. id<P>, can be
3504+
// used as constraints by extracting the underlying protocol
3505+
// types.
3506+
auto *typeAlias = dyn_cast<TypeAliasType>(result.getPointer());
3507+
if (typeAlias && typeAlias->is<ExistentialType>() &&
3508+
typeAlias->getDecl()->hasClangNode()) {
3509+
return typeAlias->getAs<ExistentialType>()->getConstraintType();
3510+
}
3511+
}
3512+
35023513
// Hack to apply context-specific @escaping to a typealias with an underlying
35033514
// function type.
35043515
if (result->is<FunctionType>())

0 commit comments

Comments
 (0)