Skip to content

[ConstraintSystem] Don't attempt dynamic member lookup on invalid base #26100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4786,6 +4786,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
Original file line number Diff line number Diff line change
@@ -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}}
}