Skip to content

Commit f459eb3

Browse files
committed
[Sema] Report exported uses of conformances that are implicitly imported
Diagnose uses of conformances in API when the conformance declaration isn't imported by the local file. This uses the existing logic checking for conformance availability combined with the implicit import check. Report it as a warning until Swift 6 where it will be an error. rdar://96437311
1 parent 82e9380 commit f459eb3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,8 @@ ERROR(conformance_from_implementation_only_module,none,
29222922
"in an extension with conditional conformances}2; "
29232923
"%select{%3 has been imported as implementation-only|"
29242924
"the conformance is declared as SPI in %3|"
2925-
"the conformance is declared as SPI}4",
2925+
"the conformance is declared as SPI|"
2926+
"%3 was not imported by this file}4",
29262927
(Type, Identifier, unsigned, Identifier, unsigned))
29272928
NOTE(assoc_conformance_from_implementation_only_module,none,
29282929
"in associated type %0 (inferred as %1)", (Type, Type))

test/Sema/implicit-import-in-inlinable-code.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ public struct ImportedType {
2323
public init() {}
2424
}
2525

26+
// Test exportability of conformance uses
27+
public protocol SomeProtocol {}
28+
public func conformanceUse(_ a: SomeProtocol) {}
29+
2630
// BEGIN libB.swift
2731
import libA
2832

2933
extension ImportedType {
3034
public func implicitlyImportedMethod() {}
3135
}
3236

37+
extension ImportedType : SomeProtocol {}
38+
3339
/// Client module
3440
// BEGIN clientFileA-Swift5.swift
3541
import libA
@@ -40,6 +46,8 @@ import libA
4046

4147
// Expected implicit imports are still fine
4248
a.localModuleMethod()
49+
50+
conformanceUse(a) // expected-warning {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file; this is an error in Swift 6}}
4351
}
4452

4553
// BEGIN clientFileA-OldCheck.swift
@@ -52,6 +60,8 @@ import libA
5260

5361
// Expected implicit imports are still fine
5462
a.localModuleMethod()
63+
64+
conformanceUse(a) // expected-warning {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file; this is an error in Swift 6}}
5565
}
5666

5767
// BEGIN clientFileA-Swift6.swift
@@ -63,6 +73,8 @@ import libA
6373

6474
// Expected implicit imports are still fine
6575
a.localModuleMethod()
76+
77+
conformanceUse(a) // expected-error {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file}}
6678
}
6779

6880
// BEGIN clientFileB.swift

0 commit comments

Comments
 (0)