Skip to content

Commit 4d5d30b

Browse files
committed
[QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
While trying to diagnose problems related to keypath components don't assume that type of the component is always correct, check before trying to see if it's bridged type or has members. Resolves: rdar://problem/33135487 (cherry picked from commit c45073e)
1 parent 448affa commit 4d5d30b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7537,6 +7537,8 @@ static bool diagnoseKeyPathComponents(ConstraintSystem *CS, KeyPathExpr *KPE,
75377537
auto performLookup = [&](Identifier componentName, SourceLoc componentNameLoc,
75387538
Type &lookupType) -> LookupResult {
75397539
assert(currentType && "Non-beginning state must have a type");
7540+
if (!currentType->mayHaveMembers())
7541+
return LookupResult();
75407542

75417543
// Determine the type in which the lookup should occur. If we have
75427544
// a bridged value type, this will be the Objective-C class to
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
enum State<StateType> {
4+
func put<StateType>() -> StateType {}
5+
func put<T>(keyPath: WritableKeyPath<StateType, T>, projection: T) {
6+
put(keyPath: \.age, projection: {})
7+
}
8+
}

0 commit comments

Comments
 (0)