File: missing-import-inlinable-code.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (111 lines) | stat: -rw-r--r-- 5,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/// Report the use in API of indirectly or implicitly imported decls.

// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s

// RUN: %target-swift-frontend -emit-module %t/empty.swift -module-name empty -o %t/empty.swiftmodule \
// RUN:   -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/libA.swift -module-name libA -o %t/libA.swiftmodule \
// RUN:   -enable-library-evolution
// RUN: %target-swift-frontend -emit-module %t/libB.swift -module-name libB -o %t/libB.swiftmodule -I %t \
// RUN:   -enable-library-evolution

/// In pre-Swift 6, this is a warning where there's no implementation-only import present.
// RUN: %target-swift-frontend -emit-module %t/clientFileA-Swift5.swift %t/clientFileB.swift -module-name client -o %t/client.swiftmodule -I %t -verify \
// RUN:   -enable-library-evolution

/// In pre-Swift 6, this remains an error when there's an implementation-only import present.
// RUN: %target-swift-frontend -emit-module %t/clientFileA-OldCheck.swift %t/clientFileB.swift -module-name client -o %t/client.swiftmodule -I %t -verify \
// RUN:   -enable-library-evolution

/// In Swift 6, it's an error.
// RUN: %target-swift-frontend -emit-module %t/clientFileA-Swift6.swift %t/clientFileB.swift -module-name client -o %t/client.swiftmodule -I %t -verify -swift-version 6 \
// RUN:   -enable-library-evolution

/// The swiftinterface is broken by the missing import without the workaround.
// RUN: %target-swift-emit-module-interface(%t/ClientBroken.swiftinterface)  %t/clientFileA-Swift5.swift %t/clientFileB.swift -I %t -disable-print-missing-imports-in-module-interface
// RUN: not %target-swift-typecheck-module-from-interface(%t/ClientBroken.swiftinterface) -I %t

/// The swiftinterface parses fine with the workaround adding the missing imports.
// RUN: %target-swift-emit-module-interface(%t/ClientFixed.swiftinterface)  %t/clientFileA-Swift5.swift %t/clientFileB.swift -I %t
// RUN: %target-swift-typecheck-module-from-interface(%t/ClientFixed.swiftinterface) -I %t

/// The inserted missing imports should be aliased.
// RUN: %target-swift-emit-module-interface(%t/ClientFixed.swiftinterface) %t/clientFileA-Swift5.swift %t/clientFileB.swift -I %t -alias-module-names-in-module-interface
// RUN: %target-swift-typecheck-module-from-interface(%t/ClientFixed.swiftinterface) -I %t
// RUN: cat %t/ClientFixed.swiftinterface | %FileCheck -check-prefix ALIASED %s
// ALIASED: import Module___libB

// BEGIN empty.swift

// BEGIN libA.swift
public struct ImportedType {
    public init() {}
}

// Test exportability of conformance uses
public protocol SomeProtocol {}
public func conformanceUse(_ a: SomeProtocol) {}

// BEGIN libB.swift
import libA

extension ImportedType {
    public func implicitlyImportedMethod() {}
}

extension ImportedType : SomeProtocol {}

/// Client module
// BEGIN clientFileA-Swift5.swift
public import libA

@inlinable public func bar() {
  let a = ImportedType()
  a.implicitlyImportedMethod() // expected-warning {{instance method 'implicitlyImportedMethod()' cannot be used in an '@inlinable' function because 'libB' was not imported by this file; this is an error in the Swift 6 language mode}}
  // expected-note@-1 {{The missing import of module 'libB' will be added implicitly}}

  // Expected implicit imports are still fine
  a.localModuleMethod()

  conformanceUse(a) // expected-warning {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file; this is an error in the Swift 6 language mode}}
  // expected-note@-1 {{The missing import of module 'libB' will be added implicitly}}
}

// BEGIN clientFileA-OldCheck.swift
public import libA
@_implementationOnly import empty
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}

@inlinable public func bar() {
  let a = ImportedType()
  a.implicitlyImportedMethod() // expected-error {{instance method 'implicitlyImportedMethod()' cannot be used in an '@inlinable' function because 'libB' was not imported by this file}}

  // Expected implicit imports are still fine
  a.localModuleMethod()

  conformanceUse(a) // expected-warning {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file; this is an error in the Swift 6 language mode}}
  // expected-note@-1 {{The missing import of module 'libB' will be added implicitly}}
}

// BEGIN clientFileA-Swift6.swift
public import libA

@inlinable public func bar() {
  let a = ImportedType()
  a.implicitlyImportedMethod() // expected-error {{instance method 'implicitlyImportedMethod()' cannot be used in an '@inlinable' function because 'libB' was not imported by this file}}

  // Expected implicit imports are still fine
  a.localModuleMethod()

  conformanceUse(a) // expected-error {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file}}
}

// BEGIN clientFileB.swift
@_implementationOnly import libB
// expected-warning @-1 {{'@_implementationOnly' is deprecated, use 'internal import' instead}}
public import libA
extension ImportedType {
    public func localModuleMethod() {}
}