Allowing forming WritableKeyPath to read-only value in Swift 3/4.

We inadvertantly allowed this in the past, so continue to do so when
compiling in Swift 3/4 mode to avoid suddenly breaking existing code.

The diagnostic here is pretty bad, and I've opened issues for that as
well as providing some kind of deprecation warning for this so that
even under Swift 3/4 mode we alert users that this is unsupported.

rdar://problem/39802797
This commit is contained in:
Mark Lacey
2018-05-08 12:35:41 -07:00
parent efa36efcd0
commit 83ebd71644
5 changed files with 46 additions and 4 deletions

View File

@@ -514,8 +514,9 @@ struct VisibilityTesting {
toHaveType: Exactly<WritableKeyPath<VisibilityTesting, Int>>.self)
expect(&yRef,
toHaveType: Exactly<WritableKeyPath<VisibilityTesting, Int>>.self)
// Allow WritableKeyPath for Swift 3/4 only.
expect(&zRef,
toHaveType: Exactly<KeyPath<VisibilityTesting, Int>>.self)
toHaveType: Exactly<WritableKeyPath<VisibilityTesting, Int>>.self)
}
func inPrivateContext() {
@@ -536,8 +537,9 @@ struct VisibilityTesting2 {
var xRef = \VisibilityTesting.x
var yRef = \VisibilityTesting.y
var zRef = \VisibilityTesting.z
// Allow WritableKeyPath for Swift 3/4 only.
expect(&xRef,
toHaveType: Exactly<KeyPath<VisibilityTesting, Int>>.self)
toHaveType: Exactly<WritableKeyPath<VisibilityTesting, Int>>.self)
expect(&yRef,
toHaveType: Exactly<WritableKeyPath<VisibilityTesting, Int>>.self)
expect(&zRef,