Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2250] Generated ObjC header doesn't import Foundation if only bridged types are used #44857

Closed
jckarter opened this issue Aug 1, 2016 · 12 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers PrintAsClang Area → compiler: The PrintAsClang library

Comments

@jckarter
Copy link
Member

jckarter commented Aug 1, 2016

Previous ID SR-2250
Radar rdar://problem/41156454
Original Reporter @jckarter
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, PrintAsObjC, StarterBug
Assignee Mani (JIRA)
Priority Medium

md5: 357e61899ba86f33c9bac25b20bb82d9

is duplicated by:

  • SR-8217 Generated ObjC header contains syntax errors with certain declarations
  • SR-9574 Generated header doesn't import Foundation when adopting throwing method.

Issue Description:

If an ObjC header is generated from a Swift interface that only uses standard library bridged types, then Foundation is not imported in the generated header, leaving NSArray and friends undefined.

@belkadan
Copy link
Contributor

belkadan commented Apr 6, 2018

This actually happened to someone: https://twitter.com/avbelow/status/982258484371537921. Attached their test project.

I'm going to say that it's not worth trying to be clever here. We should just #import <Foundation/Foundation.h> instead of the minimal <objc/NSObject.h> that's there today. (Note that this uses old-style import syntax rather than module syntax so that it doesn't make the problem of working with Objective-C++ worse.)

Tagging as a StarterBug, because anyone can make that change. Meanwhile, a workaround is to make sure you import Foundation before using the generated header.

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 8, 2018

Comment by Mani Ramezan (JIRA)

@belkadan Hey, I'm interested in picking up this ticket as my first attempt to contribute to Swift compiler. Since it's assigned to you, was wondering to check if it's ok to assign it to myself and try to apply the suggested change.

@swift-ci
Copy link
Collaborator

Comment by Mani Ramezan (JIRA)

@belkadan I added #import <Foundation/Foundation.h> and the tests started failing as they all fail to find:

fatal error:
 'Foundation/Foundation.h' file not found

Do you happen to know a sample for similar situation I can look into for fixing tests? I tried to find some but wasn't successful, so far have found -include foundation.h or asking to use mock sdk that also didn't work.

@belkadan
Copy link
Contributor

Ah, which tests are failing? I would have expected all the PrintAsObjC tests to be using the real SDK, but maybe I'm misremembering.

@belkadan
Copy link
Contributor

Oh. Definitely misremembering. *sigh* I guess we could move the mock SDK's Foundation.h, but that could cause a lot of churn. Hm…maybe we can put a dummy Foundation/Foundation.h inside test/PrintAsObjC/Inputs/, and then add that as an include path everywhere?

(and then that header would just turn around and import the mock Foundation as <Foundation.h>)

@swift-ci
Copy link
Collaborator

Comment by Mani Ramezan (JIRA)

Almost all of the tests for PrintAsObjC fail on the last check, // RUN: %check-in-clang %t/Foo.h check. Putting a dummy Foundation/Foundation.h sounds good, let me look into that approach and see if I can have tests passing with that trick

@belkadan
Copy link
Contributor

Note that %check-in-clang is defined in the lit.local.cfg file; feel free to modify that as necessary.

@swift-ci
Copy link
Collaborator

Comment by Mani Ramezan (JIRA)

Thanks a lot for that last tip, it helped a lot. I could modify tests and fix the failing ones: 17615

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 6, 2018

Comment by Mani Ramezan (JIRA)

Applied the fix and submitted this PR

@belkadan
Copy link
Contributor

belkadan commented Jul 6, 2018

Sorry, please don't mark the bug as resolved until the PR is merged!

(And sorry for not seeing the PR until now. Your link is broken, which confused me.)

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 6, 2018

Comment by Mani Ramezan (JIRA)

Re-opening as the PR hasn't been merged, yet

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 6, 2018

Comment by Mani Ramezan (JIRA)

Thanks for checking. Sorry for the PR link, not sure why it's broken. When I copy/paste in the URL it works, but when I click on it here it's broken. My bad. I also reverted the issue to "In Progress".

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers PrintAsClang Area → compiler: The PrintAsClang library
Projects
None yet
Development

No branches or pull requests

3 participants