Skip to content

Commit 33a987f

Browse files
authored
Merge pull request #60008 from xymus/implicit-import-conformances
[Sema] Report exported uses of conformances that are implicitly imported
2 parents 872d4ff + f459eb3 commit 33a987f

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
@@ -2919,7 +2919,8 @@ ERROR(conformance_from_implementation_only_module,none,
29192919
"in an extension with conditional conformances}2; "
29202920
"%select{%3 has been imported as implementation-only|"
29212921
"the conformance is declared as SPI in %3|"
2922-
"the conformance is declared as SPI}4",
2922+
"the conformance is declared as SPI|"
2923+
"%3 was not imported by this file}4",
29232924
(Type, Identifier, unsigned, Identifier, unsigned))
29242925
NOTE(assoc_conformance_from_implementation_only_module,none,
29252926
"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
@@ -25,13 +25,19 @@ public struct ImportedType {
2525
public init() {}
2626
}
2727

28+
// Test exportability of conformance uses
29+
public protocol SomeProtocol {}
30+
public func conformanceUse(_ a: SomeProtocol) {}
31+
2832
// BEGIN libB.swift
2933
import libA
3034

3135
extension ImportedType {
3236
public func implicitlyImportedMethod() {}
3337
}
3438

39+
extension ImportedType : SomeProtocol {}
40+
3541
/// Client module
3642
// BEGIN clientFileA-Swift5.swift
3743
import libA
@@ -42,6 +48,8 @@ import libA
4248

4349
// Expected implicit imports are still fine
4450
a.localModuleMethod()
51+
52+
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}}
4553
}
4654

4755
// BEGIN clientFileA-OldCheck.swift
@@ -54,6 +62,8 @@ import libA
5462

5563
// Expected implicit imports are still fine
5664
a.localModuleMethod()
65+
66+
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}}
5767
}
5868

5969
// BEGIN clientFileA-Swift6.swift
@@ -65,6 +75,8 @@ import libA
6575

6676
// Expected implicit imports are still fine
6777
a.localModuleMethod()
78+
79+
conformanceUse(a) // expected-error {{cannot use conformance of 'ImportedType' to 'SomeProtocol' here; 'libB' was not imported by this file}}
6880
}
6981

7082
// BEGIN clientFileB.swift

0 commit comments

Comments
 (0)