[TypeCheckEffects] AbstractFunction: Parameter types should be mapped into context

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
(cherry picked from commit 32b97d0e2a)
(cherry picked from commit 7f652915d9)
This commit is contained in:
Pavel Yaskevich
2025-08-12 17:14:50 -07:00
parent 55f82ea3a0
commit bbb11ec272
2 changed files with 29 additions and 1 deletions

View File

@@ -395,7 +395,10 @@ public:
}
case Kind::Closure: return getClosure()->getType();
case Kind::Parameter:
return getParameter()->getInterfaceType()->lookThroughAllOptionalTypes();
auto *param = getParameter();
auto *dc = param->getDeclContext();
return dc->mapTypeIntoContext(param->getInterfaceType())
->lookThroughAllOptionalTypes();
}
llvm_unreachable("bad kind");
}

View File

@@ -0,0 +1,25 @@
// RUN: %target-typecheck-verify-swift
protocol Definition {
associatedtype Delegate
}
enum Kind {
case normal
case other
}
struct Payload {
}
extension Definition where Delegate == ((Kind, Payload) -> Void) {
static func invokeDelegate(_ delegate: Delegate, kind: Kind, payload: Payload) {
delegate(kind, payload)
}
}
extension Definition where Delegate == ((Kind, Payload) -> Void)? {
static func invokeOptionalDelegate(_ delegate: Delegate, kind: Kind, payload: Payload) {
delegate?(kind, payload)
}
}