-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Don't warn on package imports providing a type extended by a package extension #73125
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
// RUN: %target-swift-frontend -emit-module %t/ExtendedDefinitionNonPublic.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/UnusedImport.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/UnusedPackageImport.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/ExtendedPackageTypeImport.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/ImportNotUseFromAPI.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/ImportUsedInPackage.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/ExportedUnused.swift -o %t -I %t | ||
|
@@ -96,6 +97,9 @@ public struct NonPublicExtendedType {} | |
//--- UnusedImport.swift | ||
|
||
//--- UnusedPackageImport.swift | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's imported but nothing it would contain would be used, but the import does show the diagnostic that we're testing. I could have had a single Empty.swift file and compile it into many different modules, but I find it useful to have a file with the module name. |
||
//--- ExtendedPackageTypeImport.swift | ||
|
||
public struct ExtendedPackageType {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: comment above, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that warning would be appropriate then as an empty extension would be internal or below.
It would fall in the same scenario as extending the type with internal decls where there's no requirement to make the import package or public as these services are not visible to other modules. Does that make sense or am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. For some reason I thought the default access level of the extension is whatever access level its nominal type has, but it looks to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
//--- ImportNotUseFromAPI.swift | ||
public struct NotAnAPIType {} | ||
|
@@ -143,6 +147,7 @@ package import UnusedImport // expected-warning {{package import of 'UnusedImpor | |
// expected-warning @-1 {{module 'UnusedImport' is imported as 'public' from the same file; this 'package' access level will be ignored}} | ||
|
||
package import UnusedPackageImport // expected-warning {{package import of 'UnusedPackageImport' was not used in package declarations}} {{1-9=}} | ||
package import ExtendedPackageTypeImport | ||
public import ImportNotUseFromAPI // expected-warning {{public import of 'ImportNotUseFromAPI' was not used in public declarations or inlinable code}} {{1-8=}} | ||
public import ImportUsedInPackage // expected-warning {{public import of 'ImportUsedInPackage' was not used in public declarations or inlinable code}} {{1-7=package}} | ||
|
||
|
@@ -241,6 +246,10 @@ public protocol Countable { | |
extension Extended: Countable { // expected-remark {{struct 'Extended' is imported via 'RetroactiveConformance'}} | ||
} | ||
|
||
extension ExtendedPackageType { // expected-remark {{struct 'ExtendedPackageType' is imported via 'ExtendedPackageTypeImport'}} | ||
package func useExtendedPackageType() { } | ||
} | ||
|
||
/// Tests for imports of clang modules. | ||
//--- module.modulemap | ||
module ClangSimpleUnused { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be another check to see if this ED doesn't have members but the nominal type it's extending has a package access level; otherwise the warning will still be thrown.