Skip to content

Commit 5e92df0

Browse files
Merge pull request #71470 from nate-chandler/bitwise-copyable/same-file
[BitwiseCopyable] Require conformance in same module as declaration.
2 parents bafa7f1 + ce6c259 commit 5e92df0

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
@@ -7635,6 +7635,9 @@ NOTE(add_nominal_bitwise_copyable_conformance,none,
76357635
NOTE(add_generic_parameter_non_bitwise_copyable_conformance,none,
76367636
"consider making generic parameter %0 conform to the 'BitwiseCopyable' protocol",
76377637
(Type))
7638+
ERROR(bitwise_copyable_outside_module,none,
7639+
"conformance to 'BitwiseCopyable' must occur in the same module as %kind0",
7640+
(const ValueDecl *))
76387641

76397642
// -- older ones below --
76407643

lib/Sema/TypeCheckBitwise.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,13 @@ bool swift::checkBitwiseCopyableConformance(ProtocolConformance *conformance,
391391
return false;
392392
}
393393

394+
// BitwiseCopyable must be added in the same source file.
395+
auto conformanceDecl = conformanceDC->getAsDecl();
396+
if (conformanceDecl->getModuleContext() != nominal->getModuleContext()) {
397+
conformanceDecl->diagnose(diag::bitwise_copyable_outside_module, nominal);
398+
return true;
399+
}
400+
394401
auto check = isImplicit ? BitwiseCopyableCheck::Implicit
395402
: BitwiseCopyableCheck::Explicit;
396403

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)