Skip to content

Commit 4847ec9

Browse files
committed
[AST/TypeChecker] Add more asserts to make sure types don't get into AST
1 parent 9665091 commit 4847ec9

File tree

9 files changed

+15
-3
lines changed

9 files changed

+15
-3
lines changed

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,7 @@ ReferenceStorageType *ReferenceStorageType::get(Type T,
28112811
ReferenceOwnership ownership,
28122812
const ASTContext &C) {
28132813
assert(!T->hasTypeVariable()); // not meaningful in type-checker
2814+
assert(!T->hasHole());
28142815
switch (optionalityOf(ownership)) {
28152816
case ReferenceOwnershipOptionality::Disallowed:
28162817
assert(!T->getOptionalObjectType() && "optional type is disallowed");
@@ -3197,6 +3198,7 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig,
31973198
ExtInfo info) {
31983199
assert(sig && "no generic signature for generic function type?!");
31993200
assert(!result->hasTypeVariable());
3201+
assert(!result->hasHole());
32003202

32013203
llvm::FoldingSetNodeID id;
32023204
GenericFunctionType::Profile(id, sig, params, result, info);

lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace {
126126
} // end anonymous namespace
127127

128128
void Expr::setType(Type T) {
129-
assert(!T || !T->hasTypeVariable());
129+
assert(!T || !T->hasTypeVariable() || !T->hasHole());
130130
Ty = T;
131131
}
132132

@@ -2001,7 +2001,7 @@ bool ClosureExpr::capturesSelfEnablingImplictSelf() const {
20012001
}
20022002

20032003
void ClosureExpr::setExplicitResultType(Type ty) {
2004-
assert(ty && !ty->hasTypeVariable());
2004+
assert(ty && !ty->hasTypeVariable() && !ty->hasHole());
20052005
ExplicitResultTypeAndBodyState.getPointer()
20062006
->setType(MetatypeType::get(ty));
20072007
}

lib/AST/SILLayout.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static void verifyFields(CanGenericSignature Sig, ArrayRef<SILField> Fields) {
5252
&& "SILLayout field cannot have an archetype type");
5353
assert(!ty->hasTypeVariable()
5454
&& "SILLayout cannot contain constraint system type variables");
55+
assert(!ty->hasHole() &&
56+
"SILLayout cannot contain constraint system type holes");
5557
if (!ty->hasTypeParameter())
5658
continue;
5759
field.getLoweredType().findIf([Sig](Type t) -> bool {

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Type QuerySubstitutionMap::operator()(SubstitutableType *type) const {
7676
}
7777

7878
void TypeLoc::setType(Type Ty) {
79-
assert(!Ty || !Ty->hasTypeVariable());
79+
assert(!Ty || !Ty->hasTypeVariable() || !Ty->hasHole());
8080
this->Ty = Ty;
8181
}
8282

lib/AST/TypeCheckRequests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ void InterfaceTypeRequest::cacheResult(Type type) const {
10131013
auto *decl = std::get<0>(getStorage());
10141014
if (type) {
10151015
assert(!type->hasTypeVariable() && "Type variable in interface type");
1016+
assert(!type->hasHole() && "Type hole in interface type");
10161017
assert(!type->is<InOutType>() && "Interface type must be materializable");
10171018
assert(!type->hasArchetype() && "Archetype in interface type");
10181019
}

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7673,6 +7673,8 @@ namespace {
76737673
componentType = solution.simplifyType(cs.getType(kp, i));
76747674
assert(!componentType->hasTypeVariable() &&
76757675
"Should not write type variable into key-path component");
7676+
assert(!componentType->hasHole() &&
7677+
"Should not write type hole into key-path component");
76767678
kp->getMutableComponents()[i].setComponentType(componentType);
76777679
}
76787680
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,10 @@ bool MissingOptionalUnwrapFailure::diagnoseAsError() {
12351235

12361236
assert(!baseType->hasTypeVariable() &&
12371237
"Base type must not be a type variable");
1238+
assert(!baseType->isHole() && "Base type must not be a type hole");
12381239
assert(!unwrappedType->hasTypeVariable() &&
12391240
"Unwrapped type must not be a type variable");
1241+
assert(!unwrappedType->isHole() && "Unwrapped type must not be a type hole");
12401242

12411243
if (!baseType->getOptionalObjectType())
12421244
return false;

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,7 @@ namespace {
36843684
if (CG.getConstraintSystem().shouldReusePrecheckedType()) {
36853685
if (expr->getType()) {
36863686
assert(!expr->getType()->hasTypeVariable());
3687+
assert(!expr->getType()->hasHole());
36873688
CG.getConstraintSystem().cacheType(expr);
36883689
return { false, expr };
36893690
}

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
416416

417417
assert(exprType && !exprType->hasTypeVariable() &&
418418
"free type variable with FreeTypeVariableBinding::GenericParameters?");
419+
assert(exprType && !exprType->hasHole() &&
420+
"type hole with FreeTypeVariableBinding::GenericParameters?");
419421

420422
if (exprType->hasError()) {
421423
recoverOriginalType();

0 commit comments

Comments
 (0)