Skip to content

Commit 86390ab

Browse files
committed
[TypeCheckEffects] Fix AbstractFunction::getType to look through all levels of optional
A member and a parameter could be wrapped in an arbitrary number of `Optional`, we need to look through all of them to get to the underlying function type. Resolves: rdar://151943924
1 parent 7ac5516 commit 86390ab

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class AbstractFunction {
386386
Type getType() const {
387387
switch (getKind()) {
388388
case Kind::Opaque:
389-
return getOpaqueFunction()->getType()->lookThroughSingleOptionalType();
389+
return getOpaqueFunction()->getType()->lookThroughAllOptionalTypes();
390390
case Kind::Function: {
391391
auto *AFD = getFunction();
392392
if (AFD->hasImplicitSelfDecl() && AppliedSelf)
@@ -395,8 +395,7 @@ class AbstractFunction {
395395
}
396396
case Kind::Closure: return getClosure()->getType();
397397
case Kind::Parameter:
398-
return getParameter()->getInterfaceType()
399-
->lookThroughSingleOptionalType();
398+
return getParameter()->getInterfaceType()->lookThroughAllOptionalTypes();
400399
}
401400
llvm_unreachable("bad kind");
402401
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@propertyWrapper
4+
struct Weak<Value> {
5+
var wrappedValue: Value? { fatalError() }
6+
}
7+
8+
struct WeakStorage<Item: Hashable> {
9+
@Weak var action: ((Set<Item>) -> Void)??
10+
}
11+
12+
final class Test {
13+
var storage: WeakStorage<AnyHashable> = .init()
14+
15+
func test(items: Set<AnyHashable>) {
16+
storage.action??(items)
17+
}
18+
}

0 commit comments

Comments
 (0)