Skip to content

Commit d81f148

Browse files
committed
[NFC] Fixup TypeChecker::getOptionalType To Not Return Type()
1 parent bd6724c commit d81f148

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,7 @@ namespace {
24042404
}
24052405

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

24082409
if (oneWayVarType) {
24092410
oneWayVarType =
@@ -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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6889,6 +6889,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
68896889
TVO_CanBindToLValue |
68906890
TVO_CanBindToNoEscape);
68916891
Type optTy = TypeChecker::getOptionalType(SourceLoc(), innerTV);
6892+
assert(!optTy->hasError());
68926893
SmallVector<Constraint *, 2> optionalities;
68936894
auto nonoptionalResult = Constraint::createFixed(
68946895
*this, ConstraintKind::Bind,

lib/Sema/TypeCheckType.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Type TypeChecker::getOptionalType(SourceLoc loc, Type elementType) {
374374
ASTContext &ctx = elementType->getASTContext();
375375
if (!ctx.getOptionalDecl()) {
376376
ctx.Diags.diagnose(loc, diag::sugar_type_not_found, 1);
377-
return Type();
377+
return ErrorType::get(ctx);
378378
}
379379

380380
return OptionalType::get(elementType);
@@ -3342,14 +3342,16 @@ Type TypeResolver::resolveOptionalType(OptionalTypeRepr *repr,
33423342
TypeResolutionOptions elementOptions = options.withoutContext(true);
33433343
elementOptions.setContext(TypeResolverContext::ImmediateOptionalTypeArgument);
33443344

3345-
// The T in T? is a generic type argument and therefore always an AST type.
3346-
// FIXME: diagnose non-materializability of element type!
33473345
Type baseTy = resolveType(repr->getBase(), elementOptions);
3348-
if (!baseTy || baseTy->hasError()) return baseTy;
3346+
if (!baseTy || baseTy->hasError()) {
3347+
return ErrorType::get(Context);
3348+
}
33493349

33503350
auto optionalTy = TypeChecker::getOptionalType(repr->getQuestionLoc(),
33513351
baseTy);
3352-
if (!optionalTy) return ErrorType::get(Context);
3352+
if (optionalTy->hasError()) {
3353+
return ErrorType::get(Context);
3354+
}
33533355

33543356
return optionalTy;
33553357
}
@@ -3412,17 +3414,16 @@ Type TypeResolver::resolveImplicitlyUnwrappedOptionalType(
34123414
TypeResolutionOptions elementOptions = options.withoutContext(true);
34133415
elementOptions.setContext(TypeResolverContext::ImmediateOptionalTypeArgument);
34143416

3415-
// The T in T! is a generic type argument and therefore always an AST type.
3416-
// FIXME: diagnose non-materializability of element type!
34173417
Type baseTy = resolveType(repr->getBase(), elementOptions);
3418-
if (!baseTy || baseTy->hasError()) return baseTy;
3419-
3420-
Type uncheckedOptionalTy;
3421-
uncheckedOptionalTy = TypeChecker::getOptionalType(repr->getExclamationLoc(),
3422-
baseTy);
3418+
if (!baseTy || baseTy->hasError()) {
3419+
return ErrorType::get(Context);
3420+
}
34233421

3424-
if (!uncheckedOptionalTy)
3422+
Type uncheckedOptionalTy =
3423+
TypeChecker::getOptionalType(repr->getExclamationLoc(), baseTy);
3424+
if (uncheckedOptionalTy->hasError()) {
34253425
return ErrorType::get(Context);
3426+
}
34263427

34273428
return uncheckedOptionalTy;
34283429
}

0 commit comments

Comments
 (0)