Skip to content

Commit ce6c259

Browse files
committed
[BitwiseCopyable] Req conformance in decl module.
Don't allow conformances to `BitwiseCopyable` to be declared in other modules.
1 parent a679bbc commit ce6c259

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7629,6 +7629,9 @@ NOTE(add_nominal_bitwise_copyable_conformance,none,
76297629
NOTE(add_generic_parameter_non_bitwise_copyable_conformance,none,
76307630
"consider making generic parameter %0 conform to the 'BitwiseCopyable' protocol",
76317631
(Type))
7632+
ERROR(bitwise_copyable_outside_module,none,
7633+
"conformance to 'BitwiseCopyable' must occur in the same module as %kind0",
7634+
(const ValueDecl *))
76327635

76337636
// -- older ones below --
76347637

lib/Sema/TypeCheckBitwise.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ bool swift::checkBitwiseCopyableConformance(ProtocolConformance *conformance,
373373
return false;
374374
}
375375

376+
// BitwiseCopyable must be added in the same source file.
377+
auto conformanceDecl = conformanceDC->getAsDecl();
378+
if (conformanceDecl->getModuleContext() != nominal->getModuleContext()) {
379+
conformanceDecl->diagnose(diag::bitwise_copyable_outside_module, nominal);
380+
return true;
381+
}
382+
376383
auto check = isImplicit ? BitwiseCopyableCheck::Implicit
377384
: BitwiseCopyableCheck::Explicit;
378385

test/Sema/bitwise_copyable_resilience.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ case somebody(T)
2727
case noone
2828
}
2929

30+
public struct Integer {
31+
var value: Int
32+
}
33+
3034
//--- Downstream.swift
3135
import Library
3236

@@ -47,3 +51,4 @@ struct S_Explicit_With_Woopsional<T> : _BitwiseCopyable {
4751
func passWoopsional<T>(_ t: Woopsional<T>) { take(t) } // expected-error {{type_does_not_conform_decl_owner}}
4852
// expected-note@-15 {{where_requirement_failure_one_subst}}
4953

54+
extension Integer : @retroactive _BitwiseCopyable {} // expected-error {{bitwise_copyable_outside_module}}

0 commit comments

Comments
 (0)