Skip to content

Commit 65521b5

Browse files
committed
[Sema] Handle placeholder types in during expression type resolution
1 parent e508fb3 commit 65521b5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,6 +5024,22 @@ class OpenUnboundGenericType {
50245024
}
50255025
};
50265026

5027+
class HandlePlaceholderType {
5028+
ConstraintSystem &cs;
5029+
const ConstraintLocatorBuilder &locator;
5030+
5031+
public:
5032+
explicit HandlePlaceholderType(ConstraintSystem &cs,
5033+
const ConstraintLocatorBuilder &locator)
5034+
: cs(cs), locator(locator) {}
5035+
5036+
Type operator()() const {
5037+
return cs.createTypeVariable(
5038+
cs.getConstraintLocator(locator),
5039+
TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding | TVO_CanBindToHole);
5040+
}
5041+
};
5042+
50275043
/// Compute the shuffle required to map from a given tuple type to
50285044
/// another tuple type.
50295045
///

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,11 +1292,11 @@ namespace {
12921292
resolveTypeReferenceInExpression(TypeRepr *repr, TypeResolverContext resCtx,
12931293
const ConstraintLocatorBuilder &locator) {
12941294
// Introduce type variables for unbound generics.
1295-
const auto opener = OpenUnboundGenericType(CS, locator);
1296-
// TODO: Handle placeholders here.
1297-
const auto result =
1298-
TypeResolution::forContextual(CS.DC, resCtx, opener,
1299-
/*placeholderHandler*/ nullptr)
1295+
const auto genericOpener = OpenUnboundGenericType(CS, locator);
1296+
const auto placeholderHandler = HandlePlaceholderType(CS, locator);
1297+
const auto result = TypeResolution::forContextual(CS.DC, resCtx,
1298+
genericOpener,
1299+
placeholderHandler)
13001300
.resolveType(repr);
13011301
if (result->hasError()) {
13021302
return Type();
@@ -1561,9 +1561,8 @@ namespace {
15611561
const auto resolution = TypeResolution::forContextual(
15621562
CS.DC, options,
15631563
// Introduce type variables for unbound generics.
1564-
// TODO: Handle placeholder types
15651564
OpenUnboundGenericType(CS, locator),
1566-
/*placeholderHandler*/ nullptr);
1565+
HandlePlaceholderType(CS, locator));
15671566
const auto result = resolution.resolveType(specializations[i]);
15681567
if (result->hasError())
15691568
return Type();

0 commit comments

Comments
 (0)