File tree Expand file tree Collapse file tree 5 files changed +48
-3
lines changed Expand file tree Collapse file tree 5 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -1185,6 +1185,10 @@ class Solution {
1185
1185
// / The node -> type mappings introduced by this solution.
1186
1186
llvm::DenseMap<ASTNode, Type> nodeTypes;
1187
1187
1188
+ // / The key path component types introduced by this solution.
1189
+ llvm::DenseMap<std::pair<const KeyPathExpr *, unsigned >, TypeBase *>
1190
+ keyPathComponentTypes;
1191
+
1188
1192
// / Contextual types introduced by this solution.
1189
1193
std::vector<std::pair<ASTNode, ContextualTypeInfo>> contextualTypes;
1190
1194
@@ -1300,6 +1304,9 @@ class Solution {
1300
1304
// / Retrieve the type of the given node, as recorded in this solution.
1301
1305
Type getType (ASTNode node) const ;
1302
1306
1307
+ // / Retrieve the type of the \p ComponentIndex-th component in \p KP.
1308
+ Type getType (const KeyPathExpr *KP, unsigned ComponentIndex) const ;
1309
+
1303
1310
// / Retrieve the type of the given node as recorded in this solution
1304
1311
// / and resolve all of the type variables in contains to form a fully
1305
1312
// / "resolved" concrete type.
Original file line number Diff line number Diff line change @@ -8901,8 +8901,9 @@ bool Solution::hasType(ASTNode node) const {
8901
8901
}
8902
8902
8903
8903
bool Solution::hasType (const KeyPathExpr *KP, unsigned ComponentIndex) const {
8904
- auto &cs = getConstraintSystem ();
8905
- return cs.hasType (KP, ComponentIndex);
8904
+ assert (KP && " Expected non-null key path parameter!" );
8905
+ return keyPathComponentTypes.find (std::make_pair (KP, ComponentIndex))
8906
+ != keyPathComponentTypes.end ();
8906
8907
}
8907
8908
8908
8909
Type Solution::getType (ASTNode node) const {
@@ -8914,6 +8915,11 @@ Type Solution::getType(ASTNode node) const {
8914
8915
return cs.getType (node);
8915
8916
}
8916
8917
8918
+ Type Solution::getType (const KeyPathExpr *KP, unsigned I) const {
8919
+ assert (hasType (KP, I) && " Expected type to have been set!" );
8920
+ return keyPathComponentTypes.find (std::make_pair (KP, I))->second ;
8921
+ }
8922
+
8917
8923
Type Solution::getResolvedType (ASTNode node) const {
8918
8924
return simplifyType (getType (node));
8919
8925
}
Original file line number Diff line number Diff line change @@ -175,6 +175,9 @@ Solution ConstraintSystem::finalize() {
175
175
for (auto &nodeType : NodeTypes) {
176
176
solution.nodeTypes .insert (nodeType);
177
177
}
178
+ for (auto &keyPathComponentType : KeyPathComponentTypes) {
179
+ solution.keyPathComponentTypes .insert (keyPathComponentType);
180
+ }
178
181
179
182
// Remember contextual types.
180
183
solution.contextualTypes .assign (
Original file line number Diff line number Diff line change @@ -1347,7 +1347,7 @@ void KeyPathTypeCheckCompletionCallback::sawSolution(
1347
1347
} else {
1348
1348
// We are completing after a component. Get the previous component's result
1349
1349
// type.
1350
- BaseType = S.simplifyType (CS .getType (KeyPath, ComponentIndex - 1 ));
1350
+ BaseType = S.simplifyType (S .getType (KeyPath, ComponentIndex - 1 ));
1351
1351
}
1352
1352
1353
1353
// If ExpectedTy is a duplicate of any other result, ignore this solution.
Original file line number Diff line number Diff line change
1
+ // RUN: %swift-ide-test -code-completion -code-completion-token COMPLETE -source-filename %s | %FileCheck %s
2
+
3
+ struct Foo {
4
+ var bar : Int
5
+ }
6
+
7
+ protocol View2 { }
8
+ struct EmptyView : View2 { }
9
+
10
+ @resultBuilder public struct ViewBuilder2 {
11
+ public static func buildBlock( _ content: EmptyView ) -> EmptyView { fatalError ( ) }
12
+ }
13
+
14
+ public struct List2 {
15
+ public init ( selection: Int ? , @ViewBuilder2 content: ( ) -> EmptyView )
16
+ public init ( selection: String ? , @ViewBuilder2 content: ( ) -> EmptyView )
17
+ }
18
+
19
+ func foo( kp: ( Foo ) -> String ) { }
20
+
21
+ func foo( ) {
22
+ List2 {
23
+ foo ( kp: \. self#^COMPLETE^#)
24
+ // CHECK: Begin completions, 1 items
25
+ // CHECK-NEXT: Decl[InstanceVar]/CurrNominal: .bar[#Int#];
26
+ // CHECK-NEXT: End completions
27
+ }
28
+ . unknownMethod ( )
29
+ }
You can’t perform that action at this time.
0 commit comments