Skip to content

Commit 6e34c90

Browse files
authored
[6.2.1][TypeCheckEffects] AbstractFunction: Parameter types should be mapped… (#83954)
… into context - Explanation: Parameter type could be represented by an associated type which is bound to a concrete type by an extension, `AbstractFunction::getType()` should map it into context before returning because the construct is that it always produces a function type. - Resolves: rdar://156955193 - Main Branch PR: #83687 - Risk: Low. This is a very narrow fix that only affects situations when parameter type, represented by an associated type, is bound by an extension. - Reviewed By: @DougGregor - Testing: Added new test-cases to the suite. (cherry picked from commit 32b97d0) (cherry picked from commit 7f65291) <!-- If this pull request is targeting a release branch, please fill out the following form: https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1 Otherwise, replace this comment with a description of your changes and rationale. Provide links to external references/discussions if appropriate. If this pull request resolves any GitHub issues, link them like so: Resolves <link to issue>, resolves <link to another issue>. For more information about linking a pull request to an issue, see: https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue --> <!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci Thank you for your contribution to Swift! -->
2 parents 55f82ea + bbb11ec commit 6e34c90

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ class AbstractFunction {
395395
}
396396
case Kind::Closure: return getClosure()->getType();
397397
case Kind::Parameter:
398-
return getParameter()->getInterfaceType()->lookThroughAllOptionalTypes();
398+
auto *param = getParameter();
399+
auto *dc = param->getDeclContext();
400+
return dc->mapTypeIntoContext(param->getInterfaceType())
401+
->lookThroughAllOptionalTypes();
399402
}
400403
llvm_unreachable("bad kind");
401404
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol Definition {
4+
associatedtype Delegate
5+
}
6+
7+
enum Kind {
8+
case normal
9+
case other
10+
}
11+
12+
struct Payload {
13+
}
14+
15+
extension Definition where Delegate == ((Kind, Payload) -> Void) {
16+
static func invokeDelegate(_ delegate: Delegate, kind: Kind, payload: Payload) {
17+
delegate(kind, payload)
18+
}
19+
}
20+
21+
extension Definition where Delegate == ((Kind, Payload) -> Void)? {
22+
static func invokeOptionalDelegate(_ delegate: Delegate, kind: Kind, payload: Payload) {
23+
delegate?(kind, payload)
24+
}
25+
}

0 commit comments

Comments
 (0)