Skip to content

Commit 32b97d0

Browse files
committed
[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
1 parent 04499a7 commit 32b97d0

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)