Skip to content

Sema: Report references to missing imports from package extensions through typealiases #73498

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

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,8 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
"as property wrapper here|"
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances|"
"in an extension with public, package, or '@usableFromInline' members|"
"in an extension with conditional conformances}3 "
"because %select{%4 has been imported as implementation-only|"
"it is an SPI imported from %4|"
Expand Down
22 changes: 18 additions & 4 deletions test/Sema/missing-import-typealias.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
// RUN: %target-swift-emit-module-interface(%t/Aliases.swiftinterface) %t/Aliases.swift -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/Aliases.swiftinterface) -I %t

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

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

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

/// The swiftinterface parses fine with the workaround adding the missing imports.
// RUN: %target-swift-emit-module-interface(%t/UsesAliasesNoImportFixed.swiftinterface) %t/UsesAliasesNoImport.swift -I %t
// 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
// RUN: %target-swift-typecheck-module-from-interface(%t/UsesAliasesNoImportFixed.swiftinterface) -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/UsesAliasesNoImportFixed.package.swiftinterface) -I %t -module-name UsesAliasesNoImportFixed

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

// 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}}
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
package class InheritsFromClazzAliasPackage: ClazzAlias {}

@inlinable public func inlinableFunc() {
// 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}}
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
Expand All @@ -80,6 +85,10 @@ public class InheritsFromClazzAlias: ClazzAlias {}
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
public func takesGeneric<T: ProtoAlias>(_ t: T) {}

// 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}}
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
package func takesGenericPackage<T: ProtoAlias>(_ t: T) {}

public struct HasMembers {
// 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}}
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
Expand All @@ -92,6 +101,11 @@ extension StructAlias {
public func someFunc() {}
}

// 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}}
// expected-note@+1 {{The missing import of module 'Original' will be added implicitly}}
extension StructAlias {
package func someFuncPackage() {}
}

//--- UsesAliasesImplementationOnlyImport.swift

Expand Down