Skip to content

Sema: Fix interface type computation for observer parameters #41470

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

Closed
Closed
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: 2 additions & 4 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ bool TypeChecker::isAvailabilitySafeForConformance(
return requirementInfo.isContainedIn(witnessInfo);
}

// Returns 'nullptr' if this is the setter's 'newValue' parameter;
// Returns 'nullptr' if this is the 'newValue' or 'oldValue' parameter;
// otherwise, returns the corresponding parameter of the subscript
// declaration.
static ParamDecl *getOriginalParamFromAccessor(AbstractStorageDecl *storage,
Expand All @@ -1621,11 +1621,9 @@ static ParamDecl *getOriginalParamFromAccessor(AbstractStorageDecl *storage,
switch (accessor->getAccessorKind()) {
case AccessorKind::DidSet:
case AccessorKind::WillSet:
return nullptr;

case AccessorKind::Set:
if (param == accessorParams->get(0)) {
// This is the 'newValue' parameter.
// This is the 'newValue' or 'oldValue' parameter.
return nullptr;
}

Expand Down
6 changes: 4 additions & 2 deletions test/decl/subscript/subscripting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,20 @@ protocol ProtocolWillSetDidSet4 {
}

class DidSetInSubscript {
subscript(_: Int) -> Int {
subscript(x: Int) -> Bool {
didSet { // expected-error {{'didSet' is not allowed in subscripts}}
print("eek")
let _: Int = x
}
get {}
}
}

class WillSetInSubscript {
subscript(_: Int) -> Int {
subscript(x: Int) -> Bool {
willSet { // expected-error {{'willSet' is not allowed in subscripts}}
print("eek")
let _: Int = x
}
get {}
}
Expand Down