Skip to content

IUO: Update decl checking for result type optionality differences. #14292

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 1 commit into from
Jan 31, 2018
Merged
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
35 changes: 25 additions & 10 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4373,6 +4373,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

validateAttributes(TC, SD);

auto *TyR = SD->getElementTypeLoc().getTypeRepr();
if (TyR && TyR->getKind() == TypeReprKind::ImplicitlyUnwrappedOptional) {
auto &C = SD->getASTContext();
SD->getAttrs().add(
new (C) ImplicitlyUnwrappedOptionalAttr(/* implicit= */ true));
}

if (!checkOverrides(TC, SD)) {
// If a subscript has an override attribute but does not override
// anything, complain.
Expand Down Expand Up @@ -4415,13 +4422,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
synthesizeSetterForMutableAddressedStorage(SD, TC);
}

auto *TyR = SD->getElementTypeLoc().getTypeRepr();
if (TyR && TyR->getKind() == TypeReprKind::ImplicitlyUnwrappedOptional) {
auto &C = SD->getASTContext();
SD->getAttrs().add(
new (C) ImplicitlyUnwrappedOptionalAttr(/* implicit= */ true));
}

TC.checkDeclAttributes(SD);
}

Expand Down Expand Up @@ -5746,7 +5746,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

TypeRepr *TR = resultTL.getTypeRepr();

if (resultOTK == OTK_Optional || treatIUOResultAsError) {
bool resultIsPlainOptional = resultOTK == OTK_Optional;
if (member->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>())
resultIsPlainOptional = false;

if (resultIsPlainOptional || treatIUOResultAsError) {
if (parentResultTy->getAnyOptionalObjectType())
return;
emittedError = true;
Expand Down Expand Up @@ -6119,7 +6123,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
auto canDeclTy = declTy->getCanonicalType(genericSig);
auto canParentDeclTy = parentDeclTy->getCanonicalType(genericSig);

if (canDeclTy == canParentDeclTy) {
auto declIUOAttr =
decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
auto parentDeclIUOAttr =
parentDecl->getAttrs()
.hasAttribute<ImplicitlyUnwrappedOptionalAttr>();

if (declIUOAttr == parentDeclIUOAttr && canDeclTy == canParentDeclTy) {
matches.push_back({parentDecl, true, parentDeclTy});
hadExactMatch = true;
continue;
Expand Down Expand Up @@ -6321,8 +6331,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
(attempt == OverrideCheckingAttempt::MismatchedOptional ||
attempt == OverrideCheckingAttempt::BaseNameWithMismatchedOptional);

auto declIUOAttr =
decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
auto matchDeclIUOAttr =
matchDecl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();

// If this is an exact type match, we're successful!
if (declTy->isEqual(matchType)) {
if (declIUOAttr == matchDeclIUOAttr && declTy->isEqual(matchType)) {
// Nothing to do.

} else if (method) {
Expand Down