@@ -4373,6 +4373,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4373
4373
4374
4374
validateAttributes (TC, SD);
4375
4375
4376
+ auto *TyR = SD->getElementTypeLoc ().getTypeRepr ();
4377
+ if (TyR && TyR->getKind () == TypeReprKind::ImplicitlyUnwrappedOptional) {
4378
+ auto &C = SD->getASTContext ();
4379
+ SD->getAttrs ().add (
4380
+ new (C) ImplicitlyUnwrappedOptionalAttr (/* implicit= */ true ));
4381
+ }
4382
+
4376
4383
if (!checkOverrides (TC, SD)) {
4377
4384
// If a subscript has an override attribute but does not override
4378
4385
// anything, complain.
@@ -4415,13 +4422,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4415
4422
synthesizeSetterForMutableAddressedStorage (SD, TC);
4416
4423
}
4417
4424
4418
- auto *TyR = SD->getElementTypeLoc ().getTypeRepr ();
4419
- if (TyR && TyR->getKind () == TypeReprKind::ImplicitlyUnwrappedOptional) {
4420
- auto &C = SD->getASTContext ();
4421
- SD->getAttrs ().add (
4422
- new (C) ImplicitlyUnwrappedOptionalAttr (/* implicit= */ true ));
4423
- }
4424
-
4425
4425
TC.checkDeclAttributes (SD);
4426
4426
}
4427
4427
@@ -5746,7 +5746,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
5746
5746
5747
5747
TypeRepr *TR = resultTL.getTypeRepr ();
5748
5748
5749
- if (resultOTK == OTK_Optional || treatIUOResultAsError) {
5749
+ bool resultIsPlainOptional = resultOTK == OTK_Optional;
5750
+ if (member->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
5751
+ resultIsPlainOptional = false ;
5752
+
5753
+ if (resultIsPlainOptional || treatIUOResultAsError) {
5750
5754
if (parentResultTy->getAnyOptionalObjectType ())
5751
5755
return ;
5752
5756
emittedError = true ;
@@ -6119,7 +6123,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
6119
6123
auto canDeclTy = declTy->getCanonicalType (genericSig);
6120
6124
auto canParentDeclTy = parentDeclTy->getCanonicalType (genericSig);
6121
6125
6122
- if (canDeclTy == canParentDeclTy) {
6126
+ auto declIUOAttr =
6127
+ decl->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
6128
+ auto parentDeclIUOAttr =
6129
+ parentDecl->getAttrs ()
6130
+ .hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
6131
+
6132
+ if (declIUOAttr == parentDeclIUOAttr && canDeclTy == canParentDeclTy) {
6123
6133
matches.push_back ({parentDecl, true , parentDeclTy});
6124
6134
hadExactMatch = true ;
6125
6135
continue ;
@@ -6321,8 +6331,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
6321
6331
(attempt == OverrideCheckingAttempt::MismatchedOptional ||
6322
6332
attempt == OverrideCheckingAttempt::BaseNameWithMismatchedOptional);
6323
6333
6334
+ auto declIUOAttr =
6335
+ decl->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
6336
+ auto matchDeclIUOAttr =
6337
+ matchDecl->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
6338
+
6324
6339
// If this is an exact type match, we're successful!
6325
- if (declTy->isEqual (matchType)) {
6340
+ if (declIUOAttr == matchDeclIUOAttr && declTy->isEqual (matchType)) {
6326
6341
// Nothing to do.
6327
6342
6328
6343
} else if (method) {
0 commit comments