Skip to content

Commit 5e30445

Browse files
committed
[CSSimplify] Add special handling if specialized type comes from TypeExpr
Add a special case for `TypeExpr` due to i.e. context specialization, in such cases there is nothing for the solver to "open" so we need to form opened type map manually. Resolves: rdar://111059036
1 parent e1e933c commit 5e30445

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13544,6 +13544,38 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1354413544
auto *genericParam = typeVar->getImpl().getGenericParameter();
1354513545
openedTypes.push_back({genericParam, typeVar});
1354613546
}
13547+
} else if (locator.directlyAt<TypeExpr>()) {
13548+
auto *BGT = type1->getAs<BoundGenericType>();
13549+
if (!BGT)
13550+
return SolutionKind::Error;
13551+
13552+
decl = BGT->getDecl();
13553+
13554+
auto genericParams = BGT->getDecl()->getInnermostGenericParamTypes();
13555+
if (genericParams.size() != BGT->getGenericArgs().size())
13556+
return SolutionKind::Error;
13557+
13558+
for (unsigned i = 0, n = genericParams.size(); i != n; ++i) {
13559+
auto argType = BGT->getGenericArgs()[i];
13560+
if (auto *typeVar = argType->getAs<TypeVariableType>()) {
13561+
openedTypes.push_back({genericParams[i], typeVar});
13562+
} else {
13563+
// If we have a concrete substitution then we need to create
13564+
// a new type variable to be able to add it to the list as-if
13565+
// it is opened generic parameter type.
13566+
auto *GP = genericParams[i];
13567+
13568+
unsigned options = TVO_CanBindToNoEscape;
13569+
if (GP->isParameterPack())
13570+
options |= TVO_CanBindToPack;
13571+
13572+
auto *argVar = createTypeVariable(
13573+
getConstraintLocator(locator, LocatorPathElt::GenericArgument(i)),
13574+
options);
13575+
addConstraint(ConstraintKind::Bind, argVar, argType, locator);
13576+
openedTypes.push_back({GP, argVar});
13577+
}
13578+
}
1354713579
} else {
1354813580
// If the overload hasn't been resolved, we can't simplify this constraint.
1354913581
auto overloadLocator = getCalleeLocator(getConstraintLocator(locator));

test/decl/ext/specialize.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,15 @@ func testNestedExtensions() {
7474

7575
Tree<Int>.Branch<String>.Nest<Void>.Egg.twite()
7676
}
77+
78+
// rdar://111059036 - failed to produce a diagnostic in specialized extension
79+
struct Test {
80+
struct Key<Value> {}
81+
}
82+
83+
class State {
84+
}
85+
86+
extension Test.Key<State> {
87+
static let state = Self<State>()
88+
}

0 commit comments

Comments
 (0)