You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted this property wrapper to work as if it add a subscript.
structTest{@AddSubscript(type:[Int].self)@AddSubscript(type:String.self)@AddSubscript(type:Bool.self)@AddSubscript(type:Int.self)privatevarvalue= true
func test1(){print(_value[to:[0]])//it should work and it works.print(_value[to:""])//it should work and it works.//Error: Value of type 'Any' has no dynamic member 'subscript' using key path from root type 'Bool'print(_value[to: true])//it should work but it doesn't works!//Error: Value of type 'Any' has no dynamic member 'subscript' using key path from root type 'Bool'print(_value[to:1])//it should work but it doesn't works!letkeyPath:KeyPath<AddSubscript<Bool,Int>,Bool>= \.[to:1]letkeyPath2:KeyPath<AddSubscript<AddSubscript<Bool,Int>,Bool>,Bool>= \.[to:1]letkeyPath3:KeyPath<AddSubscript<AddSubscript<Bool,Int>,Bool>,Bool>= \.[to: true]letkeyPath4:KeyPath<AddSubscript<AddSubscript<AddSubscript<Bool,Int>,Bool>,String>,Bool>= \.[to:""]letkeyPath5:KeyPath<AddSubscript<AddSubscript<AddSubscript<Bool,Int>,Bool>,String>,Bool>= \.[to: true]//Only this causes error!//Error: Value of type 'KeyPath<AddSubscript<AddSubscript<AddSubscript<Bool, Int>, Bool>, String>, Bool>' has no dynamic member 'subscript' using key path from root type 'Bool'letkeyPath6:KeyPath<AddSubscript<AddSubscript<AddSubscript<Bool,Int>,Bool>,String>,Bool>= \.[to:1]func test2(){do{//it works.letvalue1=_value[dynamicMember: \.[to:""]]//therefore, it should work, and it works.letvalue2=_value[to:""]}do{//it works.letvalue1=_value[dynamicMember: \.[to: true]]//therefore, it should work, but doesn't work.//Error: Value of type '_' has no dynamic member 'subscript' using key path from root type 'Bool'letvalue2=_value[to: true]}}}
Especially the fail of test2 is inconsistent because I think it's correct that if the first code works, then the next code should also work.
Environment
Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
Target: x86_64-apple-darwin20.3.0
Additional Detail from JIRA
md5: bc74d89bb6a0950d1a0166faef1d7829
Issue Description:
I wrote about this behavior in the forum as a question, but it's maybe a bug.
https://forums.swift.org/t/question-limitation-in-depth-of-multiple-keypath-member-lookup/47318
At first, I prepared a property wrapper using keypath-member-lookup.
I wanted this property wrapper to work as if it add a subscript.
Especially the fail of test2 is inconsistent because I think it's correct that if the first code works, then the next code should also work.
Best regards,
The text was updated successfully, but these errors were encountered: