Skip to content

Commit 4c96f64

Browse files
authored
Merge pull request #5624 from rudkx/leaky-type-variables
2 parents ad2db14 + 3fd22c9 commit 4c96f64

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6793,6 +6793,9 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
67936793

67946794
// Find the witness we need to use.
67956795
auto type = base->getType();
6796+
assert(!type->hasTypeVariable() &&
6797+
"Building call to witness with unresolved base type!");
6798+
67966799
if (auto metaType = type->getAs<AnyMetatypeType>())
67976800
type = metaType->getInstanceType();
67986801

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,6 +3101,11 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
31013101
bool Failed = false;
31023102
SmallVector<Type, 3> TypeScratch;
31033103

3104+
// Don't allow type variables from an existing constraint system to
3105+
// leak into the new constraint system created below.
3106+
assert(!BaseTy->hasTypeVariable() &&
3107+
"Unexpected type variable in base type!");
3108+
31043109
// Prepare type substitution map.
31053110
TypeSubstitutionMap Substitutions = BaseTy->getMemberSubstitutions(ED);
31063111
auto resolveType = [&](Type Ty) {
@@ -3144,6 +3149,9 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
31443149
static bool canSatisfy(Type T1, Type T2, DeclContext &DC, ConstraintKind Kind,
31453150
bool ReplaceArchetypeWithVariables,
31463151
bool AllowFreeVariables) {
3152+
assert(!T1->hasTypeVariable() && !T2->hasTypeVariable() &&
3153+
"Unexpected type variable in constraint satisfaction testing");
3154+
31473155
std::unique_ptr<TypeChecker> CreatedTC;
31483156
// If the current ast context has no type checker, create one for it.
31493157
auto *TC = static_cast<TypeChecker*>(DC.getASTContext().getLazyResolver());

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5445,7 +5445,7 @@ bool TypeChecker::isProtocolExtensionUsable(DeclContext *dc, Type type,
54455445

54465446
// If the type still has parameters, the constrained extension is considered
54475447
// unusable.
5448-
if (type->hasTypeParameter())
5448+
if (type->hasTypeParameter() || type->hasTypeVariable())
54495449
return false;
54505450

54515451
// Set up a constraint system where we open the generic parameters of the

0 commit comments

Comments
 (0)