Skip to content

Commit 77f9c01

Browse files
committed
[CSClosure] Don't try to infer types for implicitly wrapped parameters
Update `applyPropertyWrapperToParameter` to set types to projected and wrapped values and allow `TypeVariableRefFinder` to skip decls with implicit property wrappers that are not yet resolved.
1 parent c5268e2 commit 77f9c01

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class TypeVariableRefFinder : public ASTWalker {
9797
return Action::Continue(expr);
9898

9999
if (auto *wrappedVar = var->getOriginalWrappedProperty()) {
100+
// If there is no type it means that the body of the
101+
// closure hasn't been resolved yet, so we can
102+
// just skip it and wait for \c applyPropertyWrapperToParameter
103+
// to assign types.
104+
if (wrappedVar->hasImplicitPropertyWrapper())
105+
return Action::Continue(expr);
106+
100107
auto outermostWrapperAttr =
101108
wrappedVar->getOutermostAttachedPropertyWrapper();
102109

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,13 +4511,15 @@ ConstraintSystem::applyPropertyWrapperToParameter(
45114511
auto wrappedValueType = getType(param->getPropertyWrapperWrappedValueVar());
45124512
addConstraint(ConstraintKind::PropertyWrapper, projectionType, wrappedValueType,
45134513
getConstraintLocator(param));
4514+
setType(param->getPropertyWrapperProjectionVar(), projectionType);
45144515
}
45154516

45164517
initKind = PropertyWrapperInitKind::ProjectedValue;
45174518
} else {
45184519
Type wrappedValueType = computeWrappedValueType(param, wrapperType);
45194520
addConstraint(matchKind, paramType, wrappedValueType, locator);
45204521
initKind = PropertyWrapperInitKind::WrappedValue;
4522+
setType(param->getPropertyWrapperWrappedValueVar(), wrappedValueType);
45214523
}
45224524

45234525
appliedPropertyWrappers[anchor].push_back({ wrapperType, initKind });
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
8+
struct Example: View {
9+
struct Item: Identifiable {
10+
var id: Int
11+
var title: String
12+
var isOn: Bool = .random()
13+
}
14+
15+
@State var items = [
16+
Item(id: 0, title: "")
17+
]
18+
19+
var body: some View {
20+
List {
21+
Section {
22+
ForEach($items) { $item in
23+
Toggle(item.title, isOn: $item.isOn.animation())
24+
}
25+
.onDelete { items.remove(atOffsets: $0) }
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)