NSBundle for class is incorrect for Swift generic classes in frameworks

Originator:gspiers
Number:rdar://33450609 Date Originated:21/07/2017
Status:Closed (fixed in Xcode 10 beta 5) Resolved:
Product:iOS Foundation Product Version:11.0 Beta 3
Classification:Serious bug Reproducible:Always
 
When a generic class is used in an app the init method above returns a path to the App's bundle with '/Frameworks' appended which means the generic class is unable to load any assets that are included in the framework where that generic class is defined.

Steps to Reproduce:
Run sample project that has two classes in a framework called 'Example'. The two classes return an image loaded out of the Example framework's bundle.
Notice that the generic class returns an unexpected bundle that doesn't exist.
Notice the non generic class works as expected and correctly gets the Example framework's bundle and is able to load the image.

Expected Results:
We should get the correct bundle for a given generic class when using it from a different framework or app.

Observed Results:
The app's bundle plus '/Frameworks' appended is return as the bundle's path. In this example Bundle(for: type(of: self)):

For generic classes, returns a bundle that points to 'BundleBug.app/Frameworks'.
For non generic classes, returns a bundle that points correctly to 'Example.framework'.

Version:
11.0 Beta 3, 15A5318g

Sample project:
https://github.com/gspiers/radar_33450609

Comments


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!