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-9913] Transitive dependencies and extensions of standard types #52319

Closed
swift-ci opened this issue Feb 12, 2019 · 4 comments
Closed

[SR-9913] Transitive dependencies and extensions of standard types #52319

swift-ci opened this issue Feb 12, 2019 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself duplicate Resolution: Duplicates another issue extension Feature → declarations: `extension` declarations multiple modules Flag: An issue whose reproduction requires multiple modules name lookup Area → compiler → type checker: Name lookup swift 5.8 unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 12, 2019

Previous ID SR-9913
Radar None
Original Reporter domness (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Swift 4.2

macOS 10.14.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: de2e5f6d6e1136fb7e1c9c49826300ce

duplicates:

Issue Description:

When creating a project that has a dependency on a framework, if that framework has other dependencies, and those define "public extensions" on standard types (String, Int, Date, etc...), then those extensions become available inside the root project without explicitly importing the framework.

i.e.

Project TestJim imports framework A. Framework A imports framework B.

If framework B declares any public API (that isn't an extension) then this is not accessible from TestJim project without import B in the related file. This is expected behaviour.

However, if framework B declares an extension String { public var extensionInB ... } then the TestJim project can access "someString".extensionInB without having to explicitly import B. This is not expected behaviour. We would expect this to fail to compile with the error 'String' has no member 'extensionInB'.

We have attached a small sample project TestJim to highlight this problem.

@belkadan
Copy link
Contributor

This is a longstanding issue, but fixing it would be a major source compatibility break, so we have to handle it carefully.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Feb 12, 2019

Comment by Dominic Wroblewski (JIRA)

Is there a suggested way around the issue? For it to exist over 2 years is a bit of a worry.

There must be something we can do that limits the availability of the extensions if we own A, B and the project importing them?

@belkadan
Copy link
Contributor

It doesn't stop anyone from getting any work done, so it hasn't made it to the top of the "moderate-to-major changes" list. :-/ For certain use cases, some of the ideas discussed in https://forums.swift.org/t/exported-and-fixing-import-visibility/9415 would probably help.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 21, 2020

Comment by Muhamed ALGHZAWI (JIRA)

I'm currently having the same issue, but with only a single module.

Module A defines public extensions for UIView, they are available in the main module without the need for import A.
Module A defines class Dummy, it's not available in the main module without import A.

Is this related?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue swift 5.8 name lookup Area → compiler → type checker: Name lookup unexpected behavior Bug: Unexpected behavior or incorrect output multiple modules Flag: An issue whose reproduction requires multiple modules extension Feature → declarations: `extension` declarations labels May 11, 2023
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 duplicate Resolution: Duplicates another issue extension Feature → declarations: `extension` declarations multiple modules Flag: An issue whose reproduction requires multiple modules name lookup Area → compiler → type checker: Name lookup swift 5.8 unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

No branches or pull requests

3 participants