Skip to content

Update SK_LastScoreKind to SK_KeyPathSubscript. #9996

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
May 31, 2017
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
2 changes: 1 addition & 1 deletion lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ enum ScoreKind {
/// A key path application subscript.
SK_KeyPathSubscript,

SK_LastScoreKind = SK_EmptyExistentialConversion,
SK_LastScoreKind = SK_KeyPathSubscript,
};

/// The number of score kinds.
Expand Down
57 changes: 57 additions & 0 deletions test/expr/unary/keypath/keypath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,63 @@ func testKeyPathSubscript(readonly: Z, writable: inout Z,
writable[keyPath: akp] = anyqSink2 // expected-error{{cannot assign to immutable}}
}

struct ZwithSubscript {
subscript(keyPath: KeyPath<ZwithSubscript, Int>) -> Int { return 0 }
subscript(keyPath: WritableKeyPath<ZwithSubscript, Int>) -> Int { return 0 }
subscript(keyPath: ReferenceWritableKeyPath<ZwithSubscript, Int>) -> Int { return 0 }
subscript(keyPath: PartialKeyPath<ZwithSubscript>) -> Any { return 0 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subscripts don't have significant labeled arguments unless you explicitly ask for them, so all of these declarations really declare subscript(_:). You'd have to declare subscript(keyPath kp: ...) to test overloading.

}

func testKeyPathSubscript(readonly: ZwithSubscript, writable: inout ZwithSubscript,
kp: KeyPath<ZwithSubscript, Int>,
wkp: WritableKeyPath<ZwithSubscript, Int>,
rkp: ReferenceWritableKeyPath<ZwithSubscript, Int>) {
var sink: Int
sink = readonly[keyPath: kp]
sink = writable[keyPath: kp]
sink = readonly[keyPath: wkp]
sink = writable[keyPath: wkp]
sink = readonly[keyPath: rkp]
sink = writable[keyPath: rkp]

// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
readonly[keyPath: kp] = sink // expected-error{{cannot assign to immutable expression of type 'Int'}}
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
writable[keyPath: kp] = sink // expected-error{{cannot assign to immutable expression of type 'Int'}}
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
readonly[keyPath: wkp] = sink // expected-error{{cannot assign to immutable expression of type 'Int'}}
// FIXME: silently falls back to keypath application, which seems inconsistent
writable[keyPath: wkp] = sink
// FIXME: silently falls back to keypath application, which seems inconsistent
readonly[keyPath: rkp] = sink
// FIXME: silently falls back to keypath application, which seems inconsistent
writable[keyPath: rkp] = sink

let pkp: PartialKeyPath = rkp

var anySink1 = readonly[keyPath: pkp]
expect(&anySink1, toHaveType: Exactly<Any>.self)
var anySink2 = writable[keyPath: pkp]
expect(&anySink2, toHaveType: Exactly<Any>.self)

// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
readonly[keyPath: pkp] = anySink1 // expected-error{{cannot assign to immutable expression of type 'Any'}}
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
writable[keyPath: pkp] = anySink2 // expected-error{{cannot assign to immutable expression of type 'Any'}}

let akp: AnyKeyPath = pkp

var anyqSink1 = readonly[keyPath: akp]
expect(&anyqSink1, toHaveType: Exactly<Any?>.self)
var anyqSink2 = writable[keyPath: akp]
expect(&anyqSink2, toHaveType: Exactly<Any?>.self)

// FIXME: silently falls back to keypath application, which seems inconsistent
readonly[keyPath: akp] = anyqSink1 // expected-error{{cannot assign to immutable}}
// FIXME: silently falls back to keypath application, which seems inconsistent
writable[keyPath: akp] = anyqSink2 // expected-error{{cannot assign to immutable}}
}

func testKeyPathSubscriptMetatype(readonly: Z.Type, writable: inout Z.Type,
kp: KeyPath<Z.Type, Int>,
wkp: WritableKeyPath<Z.Type, Int>,
Expand Down