Skip to content

Commit

Permalink
Merge pull request #26106 from xedin/rdar-48994658-5.1
Browse files Browse the repository at this point in the history
[5.1][ConstraintSystem] Don't attempt dynamic member lookup on invalid base
  • Loading branch information
xedin committed Jul 12, 2019
2 parents 6228147 + 30015dc commit a062b3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Sema/CSSimplify.cpp
Expand Up @@ -4681,6 +4681,10 @@ fixMemberRef(ConstraintSystem &cs, Type baseTy,
switch (*reason) {
case MemberLookupResult::UR_InstanceMemberOnType:
case MemberLookupResult::UR_TypeMemberOnInstance: {
if (choice.getKind() == OverloadChoiceKind::DynamicMemberLookup ||
choice.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup)
return nullptr;

return choice.isDecl()
? AllowTypeOrInstanceMember::create(
cs, baseTy, choice.getDecl(), memberName, locator)
Expand Down
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift

struct Ref<Value> {
static func foo(_ value: Int) {} // expected-note {{declared here}}
}

@dynamicMemberLookup
protocol RefConvertible {
associatedtype Value

var ref: Ref<Value> { get }

subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, T>) -> Ref<T> { get }
}

extension RefConvertible {
public subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, T>) -> Ref<T> {
return .init()
}
}

extension Ref : RefConvertible {
var ref: Ref { return self }
}

func rdar_48994658() {
Ref.foo() // expected-error {{missing argument for parameter #1 in call}}
}

0 comments on commit a062b3c

Please sign in to comment.