Skip to content

[NFC] TypeCheckType No Longer Returns Null #32321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ namespace {
// Make the integer literals for the parameters.
auto buildExprFromUnsigned = [&](unsigned value) {
LiteralExpr *expr = IntegerLiteralExpr::createFromUnsigned(ctx, value);
cs.setType(expr, TypeChecker::getIntType(ctx));
cs.setType(expr, ctx.getIntDecl()->getDeclaredInterfaceType());
return handleIntegerLiteralExpr(expr);
};

Expand Down Expand Up @@ -4698,7 +4698,9 @@ namespace {
StringRef(stringCopy, compatStringBuf.size()),
SourceRange(),
/*implicit*/ true);
cs.setType(stringExpr, TypeChecker::getStringType(cs.getASTContext()));
cs.setType(
stringExpr,
cs.getASTContext().getStringDecl()->getDeclaredInterfaceType());
E->setObjCStringLiteralExpr(stringExpr);
}
}
Expand Down
7 changes: 2 additions & 5 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2570,11 +2570,8 @@ bool ContextualFailure::trySequenceSubsequenceFixIts(
if (!getASTContext().getStdlibModule())
return false;

auto String = TypeChecker::getStringType(getASTContext());
auto Substring = TypeChecker::getSubstringType(getASTContext());

if (!String || !Substring)
return false;
auto String = getASTContext().getStringDecl()->getDeclaredInterfaceType();
auto Substring = getASTContext().getSubstringDecl()->getDeclaredInterfaceType();

// Substring -> String conversion
// Wrap in String.init
Expand Down
9 changes: 5 additions & 4 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ namespace {
options |= TypeResolutionFlags::AllowUnboundGenerics;
auto result = TypeResolution::forContextual(CS.DC, options)
.resolveType(repr);
if (!result || result->hasError()) {
if (result->hasError()) {
return Type();
}
return result;
Expand Down Expand Up @@ -2404,6 +2404,7 @@ namespace {
}

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

if (oneWayVarType) {
oneWayVarType =
Expand Down Expand Up @@ -2770,7 +2771,7 @@ namespace {
Type castType = TypeResolution::forContextual(
CS.DC, TypeResolverContext::InExpression)
.resolveType(isp->getCastTypeRepr());
if (!castType) {
if (castType->hasError()) {
return false;
}

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

// Require the operand to be convertible to the array type.
CS.addConstraint(ConstraintKind::Conversion,
Expand Down Expand Up @@ -3304,7 +3305,7 @@ namespace {
/// worth QoI efforts.
Type getOptionalType(SourceLoc optLoc, Type valueTy) {
auto optTy = TypeChecker::getOptionalType(optLoc, valueTy);
if (!optTy ||
if (optTy->hasError() ||
TypeChecker::requireOptionalIntrinsics(CS.getASTContext(), optLoc))
return Type();

Expand Down
12 changes: 7 additions & 5 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2426,9 +2426,9 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
static bool isStringCompatiblePointerBaseType(ASTContext &ctx,
Type baseType) {
// Allow strings to be passed to pointer-to-byte or pointer-to-void types.
if (baseType->isEqual(TypeChecker::getInt8Type(ctx)))
if (baseType->isEqual(ctx.getInt8Decl()->getDeclaredInterfaceType()))
return true;
if (baseType->isEqual(TypeChecker::getUInt8Type(ctx)))
if (baseType->isEqual(ctx.getUInt8Decl()->getDeclaredInterfaceType()))
return true;
if (baseType->isEqual(ctx.TheEmptyTupleType))
return true;
Expand Down Expand Up @@ -4926,7 +4926,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// The pointer can be converted from a string, if the element
// type is compatible.
auto &ctx = getASTContext();
if (type1->isEqual(TypeChecker::getStringType(ctx))) {
if (type1->isEqual(
ctx.getStringDecl()->getDeclaredInterfaceType())) {
auto baseTy = getFixedTypeRecursive(pointeeTy, false);

if (baseTy->isTypeVariableOrMember() ||
Expand Down Expand Up @@ -6889,6 +6890,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
TVO_CanBindToLValue |
TVO_CanBindToNoEscape);
Type optTy = TypeChecker::getOptionalType(SourceLoc(), innerTV);
assert(!optTy->hasError());
SmallVector<Constraint *, 2> optionalities;
auto nonoptionalResult = Constraint::createFixed(
*this, ConstraintKind::Bind,
Expand Down Expand Up @@ -9212,11 +9214,11 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
auto &ctx = getASTContext();
auto int8Con = Constraint::create(*this, ConstraintKind::Bind,
baseType2,
TypeChecker::getInt8Type(ctx),
ctx.getInt8Decl()->getDeclaredInterfaceType(),
getConstraintLocator(locator));
auto uint8Con = Constraint::create(*this, ConstraintKind::Bind,
baseType2,
TypeChecker::getUInt8Type(ctx),
ctx.getUInt8Decl()->getDeclaredInterfaceType(),
getConstraintLocator(locator));
auto voidCon = Constraint::create(*this, ConstraintKind::Bind,
baseType2, ctx.TheEmptyTupleType,
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
}

// Definite error-types were already diagnosed in resolveType.
if (!T || T->hasError())
if (T->hasError())
return;
attr->setProtocolType(T);

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
auto resolution = TypeResolution::forContextual(DC, options);
auto BaseTy = resolution.resolveType(InnerTypeRepr);

if (BaseTy && BaseTy->mayHaveMembers()) {
if (BaseTy->mayHaveMembers()) {
auto lookupOptions = defaultMemberLookupOptions;
if (isa<AbstractFunctionDecl>(DC) ||
isa<AbstractClosureExpr>(DC))
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ static Type validateParameterType(ParamDecl *decl) {

if (decl->isVariadic()) {
Ty = TypeChecker::getArraySliceType(decl->getStartLoc(), Ty);
if (Ty.isNull()) {
if (Ty->hasError()) {
decl->setInvalid();
return ErrorType::get(ctx);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ static Type validateTypedPattern(TypedPattern *TP, TypeResolution resolution) {
}

auto ty = resolution.resolveType(Repr);
if (!ty || ty->hasError()) {
if (ty->hasError()) {
return ErrorType::get(Context);
}

Expand Down Expand Up @@ -1233,7 +1233,7 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
TypeResolutionOptions paramOptions(TypeResolverContext::InExpression);
auto castType = TypeResolution::forContextual(dc, paramOptions)
.resolveType(IP->getCastTypeRepr());
if (!castType || castType->hasError())
if (castType->hasError())
return nullptr;
IP->setCastType(castType);

Expand Down
Loading