mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
If this is an attempt to fetch members through key path dynamic member lookup let's not try to apply any property wrapper related fixes because modifying base type would not change the result. Resolves: [SR-12520](https://bugs.swift.org/browse/SR-12520) Resolves: rdar://problem/61911108
39 lines
800 B
Swift
39 lines
800 B
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
@propertyWrapper
|
|
@dynamicMemberLookup
|
|
struct Binding<Value> {
|
|
var wrappedValue: Value
|
|
|
|
subscript<Subject>(dynamicMember keyPath: WritableKeyPath<Value, Subject>) -> Binding<Subject> {
|
|
get { fatalError() }
|
|
}
|
|
}
|
|
|
|
@propertyWrapper
|
|
struct Wrapper<Value> {
|
|
var wrappedValue: Value
|
|
var projectedValue: Binding<Value>
|
|
}
|
|
|
|
@dynamicMemberLookup class Foo {
|
|
struct State {
|
|
let value: Bool
|
|
}
|
|
|
|
let currentState: State = State(value: false)
|
|
|
|
subscript<U>(dynamicMember keyPath: KeyPath<State, U>) -> U {
|
|
return currentState[keyPath: keyPath]
|
|
}
|
|
}
|
|
|
|
struct Test {
|
|
@Wrapper var foo: Foo
|
|
|
|
func test() {
|
|
if foo.bar { // expected-error {{value of type 'Foo' has no dynamic member 'bar' using key path from root type 'Foo.State'}}
|
|
}
|
|
}
|
|
}
|