Skip to content

Commit d63d6c8

Browse files
authored
Merge pull request #73498 from xymus/missing-import-package
Sema: Report references to missing imports from package extensions through typealiases
2 parents 058018f + 12f7abc commit d63d6c8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

include/swift/AST/DiagnosticsSema.def

+2
Original file line numberDiff line numberDiff line change
@@ -3648,6 +3648,8 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
36483648
"as property wrapper here|"
36493649
"as result builder here|"
36503650
"in an extension with public or '@usableFromInline' members|"
3651+
"in an extension with conditional conformances|"
3652+
"in an extension with public, package, or '@usableFromInline' members|"
36513653
"in an extension with conditional conformances}3 "
36523654
"because %select{%4 has been imported as implementation-only|"
36533655
"it is an SPI imported from %4|"

test/Sema/missing-import-typealias.swift

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@
77
// RUN: %target-swift-emit-module-interface(%t/Aliases.swiftinterface) %t/Aliases.swift -I %t
88
// RUN: %target-swift-typecheck-module-from-interface(%t/Aliases.swiftinterface) -I %t
99

10-
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -enable-library-evolution -I %t
10+
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -enable-library-evolution -I %t -package-name pkg
1111
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesImplementationOnlyImport.swift -enable-library-evolution -I %t
1212
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesSPIOnlyImport.swift -enable-library-evolution -I %t -experimental-spi-only-imports
1313
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesWithImport.swift -enable-library-evolution -I %t
1414

1515
/// With library evolution disabled UsesAliasesNoImport.swift should compile without diagnostics.
16-
// RUN: %target-swift-frontend -typecheck %t/UsesAliasesNoImport.swift -I %t | %FileCheck %t/UsesAliasesNoImport.swift --check-prefix=CHECK-NON-RESILIENT --allow-empty
16+
// RUN: %target-swift-frontend -typecheck %t/UsesAliasesNoImport.swift -I %t -package-name pkg | %FileCheck %t/UsesAliasesNoImport.swift --check-prefix=CHECK-NON-RESILIENT --allow-empty
1717

1818
/// The swiftinterface is broken by the missing import without the workaround.
19-
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesNoImport.swiftinterface) %t/UsesAliasesNoImport.swift -I %t \
19+
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesNoImport.swiftinterface) %t/UsesAliasesNoImport.swift -I %t -package-name pkg \
2020
// RUN: -disable-print-missing-imports-in-module-interface
2121
// RUN: not %target-swift-typecheck-module-from-interface(%t/UsesAliasesNoImport.swiftinterface) -I %t
2222

2323
/// The swiftinterface parses fine with the workaround adding the missing imports.
24-
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesNoImportFixed.swiftinterface) %t/UsesAliasesNoImport.swift -I %t
24+
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesNoImportFixed.swiftinterface) %t/UsesAliasesNoImport.swift -I %t -package-name pkg -emit-package-module-interface-path %t/UsesAliasesNoImportFixed.package.swiftinterface
2525
// RUN: %target-swift-typecheck-module-from-interface(%t/UsesAliasesNoImportFixed.swiftinterface) -I %t
26+
// RUN: %target-swift-typecheck-module-from-interface(%t/UsesAliasesNoImportFixed.package.swiftinterface) -I %t -module-name UsesAliasesNoImportFixed
2627

2728
/// The module with an implementation-only import is not affected by the workaround and remains broken.
2829
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesImplementationOnlyImport.swiftinterface) %t/UsesAliasesImplementationOnlyImport.swift -I %t \
@@ -70,6 +71,10 @@ import Aliases
7071
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
7172
public class InheritsFromClazzAlias: ClazzAlias {}
7273

74+
// expected-warning@+2 {{'ClazzAlias' aliases 'Original.Clazz' and cannot be used here because 'Original' was not imported by this file; this is an error in the Swift 6 language mode}}
75+
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
76+
package class InheritsFromClazzAliasPackage: ClazzAlias {}
77+
7378
@inlinable public func inlinableFunc() {
7479
// expected-warning@+2 {{'StructAlias' aliases 'Original.Struct' and cannot be used in an '@inlinable' function because 'Original' was not imported by this file; this is an error in the Swift 6 language mode}}
7580
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
@@ -80,6 +85,10 @@ public class InheritsFromClazzAlias: ClazzAlias {}
8085
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
8186
public func takesGeneric<T: ProtoAlias>(_ t: T) {}
8287

88+
// expected-warning@+2 {{'ProtoAlias' aliases 'Original.Proto' and cannot be used here because 'Original' was not imported by this file; this is an error in the Swift 6 language mode}}
89+
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
90+
package func takesGenericPackage<T: ProtoAlias>(_ t: T) {}
91+
8392
public struct HasMembers {
8493
// expected-warning@+2 {{'WrapperAlias' aliases 'Original.Wrapper' and cannot be used as property wrapper here because 'Original' was not imported by this file; this is an error in the Swift 6 language mode}}
8594
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
@@ -92,6 +101,11 @@ extension StructAlias {
92101
public func someFunc() {}
93102
}
94103

104+
// expected-warning@+2 {{'StructAlias' aliases 'Original.Struct' and cannot be used in an extension with public, package, or '@usableFromInline' members because 'Original' was not imported by this file; this is an error in the Swift 6 language mode}}
105+
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
106+
extension StructAlias {
107+
package func someFuncPackage() {}
108+
}
95109

96110
//--- UsesAliasesImplementationOnlyImport.swift
97111

0 commit comments

Comments
 (0)