@@ -374,7 +374,7 @@ Type TypeChecker::getOptionalType(SourceLoc loc, Type elementType) {
374
374
ASTContext &ctx = elementType->getASTContext ();
375
375
if (!ctx.getOptionalDecl ()) {
376
376
ctx.Diags .diagnose (loc, diag::sugar_type_not_found, 1 );
377
- return Type ( );
377
+ return ErrorType::get (ctx );
378
378
}
379
379
380
380
return OptionalType::get (elementType);
@@ -3342,14 +3342,16 @@ Type TypeResolver::resolveOptionalType(OptionalTypeRepr *repr,
3342
3342
TypeResolutionOptions elementOptions = options.withoutContext (true );
3343
3343
elementOptions.setContext (TypeResolverContext::ImmediateOptionalTypeArgument);
3344
3344
3345
- // The T in T? is a generic type argument and therefore always an AST type.
3346
- // FIXME: diagnose non-materializability of element type!
3347
3345
Type baseTy = resolveType (repr->getBase (), elementOptions);
3348
- if (!baseTy || baseTy->hasError ()) return baseTy;
3346
+ if (!baseTy || baseTy->hasError ()) {
3347
+ return ErrorType::get (Context);
3348
+ }
3349
3349
3350
3350
auto optionalTy = TypeChecker::getOptionalType (repr->getQuestionLoc (),
3351
3351
baseTy);
3352
- if (!optionalTy) return ErrorType::get (Context);
3352
+ if (optionalTy->hasError ()) {
3353
+ return ErrorType::get (Context);
3354
+ }
3353
3355
3354
3356
return optionalTy;
3355
3357
}
@@ -3412,17 +3414,16 @@ Type TypeResolver::resolveImplicitlyUnwrappedOptionalType(
3412
3414
TypeResolutionOptions elementOptions = options.withoutContext (true );
3413
3415
elementOptions.setContext (TypeResolverContext::ImmediateOptionalTypeArgument);
3414
3416
3415
- // The T in T! is a generic type argument and therefore always an AST type.
3416
- // FIXME: diagnose non-materializability of element type!
3417
3417
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
+ }
3423
3421
3424
- if (!uncheckedOptionalTy)
3422
+ Type uncheckedOptionalTy =
3423
+ TypeChecker::getOptionalType (repr->getExclamationLoc (), baseTy);
3424
+ if (uncheckedOptionalTy->hasError ()) {
3425
3425
return ErrorType::get (Context);
3426
+ }
3426
3427
3427
3428
return uncheckedOptionalTy;
3428
3429
}
0 commit comments