Files
swift-mirror/test/Frontend/dynamic_member_lookup_limit.swift
Hamish Knight fb7f2d0ff2 [CS] Limit the number of chained @dynamicMemberLookup lookups
Set an upper bound on the number of chained lookups we attempt to
avoid spinning while trying to recursively apply the same dynamic
member lookup to itself.

rdar://157288911
2025-08-01 19:08:04 +01:00

22 lines
625 B
Swift

// RUN: %target-typecheck-verify-swift -dynamic-member-lookup-depth-limit=2
@dynamicMemberLookup
struct Lens<T> {
init() {}
subscript<U>(dynamicMember kp: KeyPath<T, U>) -> U {
fatalError()
}
}
struct S {
var x: Int
}
_ = \Lens<S>.x // Fine
_ = \Lens<Lens<S>>.x // Also fine
_ = \Lens<Lens<Lens<S>>>.x // expected-error {{could not find member 'x'; exceeded the maximum number of nested dynamic member lookups}}
_ = Lens<S>().x // Fine
_ = Lens<Lens<S>>().x // Also fine
_ = Lens<Lens<Lens<S>>>().x // expected-error {{could not find member 'x'; exceeded the maximum number of nested dynamic member lookups}}