Skip to content

Commit 15b6afc

Browse files
authored
Merge pull request #26100 from xedin/rdar-48994658
[ConstraintSystem] Don't attempt dynamic member lookup on invalid base
2 parents ff3cf3c + cd07652 commit 15b6afc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4786,6 +4786,10 @@ fixMemberRef(ConstraintSystem &cs, Type baseTy,
47864786
switch (*reason) {
47874787
case MemberLookupResult::UR_InstanceMemberOnType:
47884788
case MemberLookupResult::UR_TypeMemberOnInstance: {
4789+
if (choice.getKind() == OverloadChoiceKind::DynamicMemberLookup ||
4790+
choice.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup)
4791+
return nullptr;
4792+
47894793
return choice.isDecl()
47904794
? AllowTypeOrInstanceMember::create(
47914795
cs, baseTy, choice.getDecl(), memberName, locator)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Ref<Value> {
4+
static func foo(_ value: Int) {} // expected-note {{declared here}}
5+
}
6+
7+
@dynamicMemberLookup
8+
protocol RefConvertible {
9+
associatedtype Value
10+
11+
var ref: Ref<Value> { get }
12+
13+
subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, T>) -> Ref<T> { get }
14+
}
15+
16+
extension RefConvertible {
17+
public subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, T>) -> Ref<T> {
18+
return .init()
19+
}
20+
}
21+
22+
extension Ref : RefConvertible {
23+
var ref: Ref { return self }
24+
}
25+
26+
func rdar_48994658() {
27+
Ref.foo() // expected-error {{missing argument for parameter #1 in call}}
28+
}

0 commit comments

Comments
 (0)