[PrintAsObjC] Use of imported generics require the full definition. (#5518) #5556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: The generated Objective-C header did not properly make sure the definition of an imported Objective-C generic type was included before its use. Current support for a forward
@class
declaration isn't good enough here because that doesn't include arguments, and since any such types will be coming from Objective-C anyway (because Swift can't define Objective-C-compatible generic types) it's safe to just import the original framework. There is a workaround here, though, which is to import the necessary framework before importing the generated header in any .m files.Scope: Affects generated headers for code using Objective-C generic types other than NSArray, NSSet, and NSDictionary. (In the problem case, these headers weren't valid Objective-C.)
Issue: rdar://problem/28738008
Reviewed by: @DougGregor
Risk: This is mostly using an existing code path, just applying it to more types. This may reveal bugs where there weren't any before. Other than that, though, this should be pretty safe—the cases it's designed to affect wouldn't have compiled before.
Testing: Added a compiler regression test, verified that the original example now behaves correctly.