Files
swift-mirror/test/SILOptimizer/keypath_opt_crash.swift
Allan Shortlidge 9302cbe568 Sema: Diagnose @dynamicMemberLookup subscripts that are not accessible enough.
Since this is a source breaking change, downgrade the diagnostic to a warning
until the next language version unless library evolution is enabled, in which
case this would have resulted in a broken `.swiftinterface` and it therefore
makes sense to diagnose eagerly.

Resolves rdar://156919010.
2025-07-28 22:36:39 -07:00

35 lines
640 B
Swift

// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s
// REQUIRES: objc_interop
// Check if the optimizer does not crash.
import Foundation
@dynamicMemberLookup
public struct S {
private let x: NSXPCConnection
public subscript<T>(dynamicMember property: ReferenceWritableKeyPath<NSXPCConnection, T>) -> T {
get {
x[keyPath: property]
}
nonmutating set {
x[keyPath: property] = newValue
}
}
}
// CHECK: sil {{.*}}test_set
public func test_set(s: S) {
s.invalidationHandler = {}
}
// CHECK: sil {{.*}}test_get
public func test_get(s: S) -> (() -> ())? {
return s.invalidationHandler
}