Xcode/Clang: certain typedefs for Objective–C generics break KVC

Originator:daniel
Number:rdar://28053584 Date Originated:29-Aug-2016 11:52 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta 6 (8S201h)
Classification:Serious Bug Reproducible:Always
 
Summary:
When using a typedef for a special configuration of a generic container such as NSDictionary, there are two variants to write the typedef:
One that hides the pointer nature — `typedef ExistingClass<Qualifiers> *Alias` —  and one that requires you to remain explicit about it — `typedef ExistingClass<Qualifiers> Alias`.

The second form allows you to use `Alias` just as if it was a regular Objective–C class (e.g. you’d still include the asterisk when you declare a variable, and writing`[foo isKindOfClass:[TYPEDEFD_THING class]];` compiles just fine).
Unfortunately, if you choose this form, and declare a property of this type, this property is not KVC compliant, although it really should be.

Steps to Reproduce:
Run the unit tests of the attached sample project.


Expected Results:
The test passes.


Actual Results:
The test fails because `valueForUndefinedKey:`/`setValue:forUndefinedKey:` get called when attempting to do KVC against the property that uses the typedef form which doesn’t mask the pointer nature.

Comments

Comment from Greg Parker who wrote most of the Objective-C Runtime:

https://twitter.com/gparker/status/771106093648928768

@steipete IIRC this is a known problem with typedefs and @encode and can't be fixed.

Sample project on Github

Sample project can be found on the PSPDFKit-labs radar repository on GitHub:

https://github.com/PSPDFKit-labs/radar.apple.com


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!