Files
swift-mirror/test/expr/unary/keypath/keypath-availability.swift
Joe Groff 2e1b6e7070 Sema: KeyPath literals should be read-only when referring to unavailable setters.
Part of rdar://problem/65152582, where key paths were generating references to setters in contexts where they weren't
available.
2020-07-10 10:33:55 -07:00

36 lines
1.0 KiB
Swift

// RUN: %target-swift-frontend -target x86_64-apple-macosx10.9 -typecheck -verify %s
// REQUIRES: OS=macosx
struct Butt {
var setter_conditionally_available: Int {
get { fatalError() }
@available(macOS 10.10, *)
set { fatalError() }
}
}
func assertExactType<T>(of _: inout T, is _: T.Type) {}
@available(macOS 10.9, *)
public func unavailableSetterContext() {
var kp = \Butt.setter_conditionally_available
assertExactType(of: &kp, is: KeyPath<Butt, Int>.self)
}
@available(macOS 10.10, *)
public func availableSetterContext() {
var kp = \Butt.setter_conditionally_available
assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self)
}
@available(macOS 10.9, *)
public func conditionalAvailableSetterContext() {
if #available(macOS 10.10, *) {
var kp = \Butt.setter_conditionally_available
assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self)
} else {
var kp = \Butt.setter_conditionally_available
assertExactType(of: &kp, is: KeyPath<Butt, Int>.self)
}
}