Skip to content

Commit 080bea5

Browse files
authored
Merge pull request #32321 from CodaFi/type-check
[NFC] TypeCheckType No Longer Returns Null
2 parents 86baa41 + 0023695 commit 080bea5

File tree

12 files changed

+141
-170
lines changed

12 files changed

+141
-170
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ namespace {
24882488
// Make the integer literals for the parameters.
24892489
auto buildExprFromUnsigned = [&](unsigned value) {
24902490
LiteralExpr *expr = IntegerLiteralExpr::createFromUnsigned(ctx, value);
2491-
cs.setType(expr, TypeChecker::getIntType(ctx));
2491+
cs.setType(expr, ctx.getIntDecl()->getDeclaredInterfaceType());
24922492
return handleIntegerLiteralExpr(expr);
24932493
};
24942494

@@ -4698,7 +4698,9 @@ namespace {
46984698
StringRef(stringCopy, compatStringBuf.size()),
46994699
SourceRange(),
47004700
/*implicit*/ true);
4701-
cs.setType(stringExpr, TypeChecker::getStringType(cs.getASTContext()));
4701+
cs.setType(
4702+
stringExpr,
4703+
cs.getASTContext().getStringDecl()->getDeclaredInterfaceType());
47024704
E->setObjCStringLiteralExpr(stringExpr);
47034705
}
47044706
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,11 +2570,8 @@ bool ContextualFailure::trySequenceSubsequenceFixIts(
25702570
if (!getASTContext().getStdlibModule())
25712571
return false;
25722572

2573-
auto String = TypeChecker::getStringType(getASTContext());
2574-
auto Substring = TypeChecker::getSubstringType(getASTContext());
2575-
2576-
if (!String || !Substring)
2577-
return false;
2573+
auto String = getASTContext().getStringDecl()->getDeclaredInterfaceType();
2574+
auto Substring = getASTContext().getSubstringDecl()->getDeclaredInterfaceType();
25782575

25792576
// Substring -> String conversion
25802577
// Wrap in String.init

lib/Sema/CSGen.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ namespace {
14991499
options |= TypeResolutionFlags::AllowUnboundGenerics;
15001500
auto result = TypeResolution::forContextual(CS.DC, options)
15011501
.resolveType(repr);
1502-
if (!result || result->hasError()) {
1502+
if (result->hasError()) {
15031503
return Type();
15041504
}
15051505
return result;
@@ -2404,6 +2404,7 @@ namespace {
24042404
}
24052405

24062406
varType = TypeChecker::getOptionalType(var->getLoc(), varType);
2407+
assert(!varType->hasError());
24072408

24082409
if (oneWayVarType) {
24092410
oneWayVarType =
@@ -2770,7 +2771,7 @@ namespace {
27702771
Type castType = TypeResolution::forContextual(
27712772
CS.DC, TypeResolverContext::InExpression)
27722773
.resolveType(isp->getCastTypeRepr());
2773-
if (!castType) {
2774+
if (castType->hasError()) {
27742775
return false;
27752776
}
27762777

@@ -2938,7 +2939,7 @@ namespace {
29382939
// Try to build the appropriate type for a variadic argument list of
29392940
// the fresh element type. If that failed, just bail out.
29402941
auto array = TypeChecker::getArraySliceType(expr->getLoc(), element);
2941-
if (!array) return element;
2942+
if (array->hasError()) return element;
29422943

29432944
// Require the operand to be convertible to the array type.
29442945
CS.addConstraint(ConstraintKind::Conversion,
@@ -3304,7 +3305,7 @@ namespace {
33043305
/// worth QoI efforts.
33053306
Type getOptionalType(SourceLoc optLoc, Type valueTy) {
33063307
auto optTy = TypeChecker::getOptionalType(optLoc, valueTy);
3307-
if (!optTy ||
3308+
if (optTy->hasError() ||
33083309
TypeChecker::requireOptionalIntrinsics(CS.getASTContext(), optLoc))
33093310
return Type();
33103311

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,9 +2426,9 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
24262426
static bool isStringCompatiblePointerBaseType(ASTContext &ctx,
24272427
Type baseType) {
24282428
// Allow strings to be passed to pointer-to-byte or pointer-to-void types.
2429-
if (baseType->isEqual(TypeChecker::getInt8Type(ctx)))
2429+
if (baseType->isEqual(ctx.getInt8Decl()->getDeclaredInterfaceType()))
24302430
return true;
2431-
if (baseType->isEqual(TypeChecker::getUInt8Type(ctx)))
2431+
if (baseType->isEqual(ctx.getUInt8Decl()->getDeclaredInterfaceType()))
24322432
return true;
24332433
if (baseType->isEqual(ctx.TheEmptyTupleType))
24342434
return true;
@@ -4926,7 +4926,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
49264926
// The pointer can be converted from a string, if the element
49274927
// type is compatible.
49284928
auto &ctx = getASTContext();
4929-
if (type1->isEqual(TypeChecker::getStringType(ctx))) {
4929+
if (type1->isEqual(
4930+
ctx.getStringDecl()->getDeclaredInterfaceType())) {
49304931
auto baseTy = getFixedTypeRecursive(pointeeTy, false);
49314932

49324933
if (baseTy->isTypeVariableOrMember() ||
@@ -6889,6 +6890,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
68896890
TVO_CanBindToLValue |
68906891
TVO_CanBindToNoEscape);
68916892
Type optTy = TypeChecker::getOptionalType(SourceLoc(), innerTV);
6893+
assert(!optTy->hasError());
68926894
SmallVector<Constraint *, 2> optionalities;
68936895
auto nonoptionalResult = Constraint::createFixed(
68946896
*this, ConstraintKind::Bind,
@@ -9222,11 +9224,11 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
92229224
auto &ctx = getASTContext();
92239225
auto int8Con = Constraint::create(*this, ConstraintKind::Bind,
92249226
baseType2,
9225-
TypeChecker::getInt8Type(ctx),
9227+
ctx.getInt8Decl()->getDeclaredInterfaceType(),
92269228
getConstraintLocator(locator));
92279229
auto uint8Con = Constraint::create(*this, ConstraintKind::Bind,
92289230
baseType2,
9229-
TypeChecker::getUInt8Type(ctx),
9231+
ctx.getUInt8Decl()->getDeclaredInterfaceType(),
92309232
getConstraintLocator(locator));
92319233
auto voidCon = Constraint::create(*this, ConstraintKind::Bind,
92329234
baseType2, ctx.TheEmptyTupleType,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2853,7 +2853,7 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
28532853
}
28542854

28552855
// Definite error-types were already diagnosed in resolveType.
2856-
if (!T || T->hasError())
2856+
if (T->hasError())
28572857
return;
28582858
attr->setProtocolType(T);
28592859

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
13971397
auto resolution = TypeResolution::forContextual(DC, options);
13981398
auto BaseTy = resolution.resolveType(InnerTypeRepr);
13991399

1400-
if (BaseTy && BaseTy->mayHaveMembers()) {
1400+
if (BaseTy->mayHaveMembers()) {
14011401
auto lookupOptions = defaultMemberLookupOptions;
14021402
if (isa<AbstractFunctionDecl>(DC) ||
14031403
isa<AbstractClosureExpr>(DC))

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,7 @@ static Type validateParameterType(ParamDecl *decl) {
21012101

21022102
if (decl->isVariadic()) {
21032103
Ty = TypeChecker::getArraySliceType(decl->getStartLoc(), Ty);
2104-
if (Ty.isNull()) {
2104+
if (Ty->hasError()) {
21052105
decl->setInvalid();
21062106
return ErrorType::get(ctx);
21072107
}

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ static Type validateTypedPattern(TypedPattern *TP, TypeResolution resolution) {
705705
}
706706

707707
auto ty = resolution.resolveType(Repr);
708-
if (!ty || ty->hasError()) {
708+
if (ty->hasError()) {
709709
return ErrorType::get(Context);
710710
}
711711

@@ -1233,7 +1233,7 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
12331233
TypeResolutionOptions paramOptions(TypeResolverContext::InExpression);
12341234
auto castType = TypeResolution::forContextual(dc, paramOptions)
12351235
.resolveType(IP->getCastTypeRepr());
1236-
if (!castType || castType->hasError())
1236+
if (castType->hasError())
12371237
return nullptr;
12381238
IP->setCastType(castType);
12391239

0 commit comments

Comments
 (0)