Skip to content

Commit a144c69

Browse files
committed
Sema: Pass DeclContext down to check{Copyable,Escapable}Conformance()
1 parent f36b509 commit a144c69

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ static void tryEmitContainmentFixits(InFlightDiagnostic &&diag,
149149
}
150150

151151
/// MARK: conformance checking
152-
static bool checkInvertibleConformanceCommon(ProtocolConformance *conformance,
152+
static bool checkInvertibleConformanceCommon(DeclContext *dc,
153+
ProtocolConformance *conformance,
153154
InvertibleProtocolKind ip) {
154155
const auto kp = getKnownProtocolKind(ip);
155156
auto *proto = conformance->getProtocol();
@@ -170,7 +171,7 @@ static bool checkInvertibleConformanceCommon(ProtocolConformance *conformance,
170171
// written in an extension, then we do not raise an error.
171172
auto inverseMarking = nom->hasInverseMarking(ip);
172173
if (inverseMarking.isAnyExplicit()) {
173-
if (conformance->getDeclContext() == nom) {
174+
if (dc == nom) {
174175
ctx.Diags.diagnose(inverseMarking.getLoc(),
175176
diag::inverse_but_also_conforms,
176177
nom, getProtocolName(kp));
@@ -260,20 +261,21 @@ static bool checkInvertibleConformanceCommon(ProtocolConformance *conformance,
260261
// This nominal cannot conform to IP if it contains storage that does not
261262
// conform to IP.
262263
bool lacksMatchingStorage =
263-
LacksMatchingStorage(nom, conformance->getDeclContext(),
264-
ip, /*diagnose=*/true).visit();
264+
LacksMatchingStorage(nom, dc, ip, /*diagnose=*/true).visit();
265265
conforms &= !lacksMatchingStorage;
266266

267267
return conforms;
268268
}
269269

270-
bool swift::checkEscapableConformance(ProtocolConformance *conformance) {
271-
return checkInvertibleConformanceCommon(conformance,
270+
bool swift::checkEscapableConformance(DeclContext *dc,
271+
ProtocolConformance *conformance) {
272+
return checkInvertibleConformanceCommon(dc, conformance,
272273
InvertibleProtocolKind::Escapable);
273274
}
274275

275-
bool swift::checkCopyableConformance(ProtocolConformance *conformance) {
276-
return checkInvertibleConformanceCommon(conformance,
276+
bool swift::checkCopyableConformance(DeclContext *dc,
277+
ProtocolConformance *conformance) {
278+
return checkInvertibleConformanceCommon(dc, conformance,
277279
InvertibleProtocolKind::Copyable);
278280
}
279281

lib/Sema/TypeCheckInvertible.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ class StorageVisitor {
3131
virtual ~StorageVisitor() = default;
3232
};
3333

34-
/// \returns true if the conformance to Copyable was successfully validated.
35-
bool checkCopyableConformance(ProtocolConformance *conformance);
34+
/// Checks that all stored properties or associated values are Copyable.
35+
bool checkCopyableConformance(DeclContext *dc,
36+
ProtocolConformance *conformance);
3637

37-
/// \returns true if the conformance to Escapable was successfully validated.
38-
bool checkEscapableConformance(ProtocolConformance *conformance);
38+
/// Checks that all stored properties or associated values are Escapable.
39+
bool checkEscapableConformance(DeclContext *dc,
40+
ProtocolConformance *conformance);
3941
}
4042

4143

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6106,10 +6106,10 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61066106
tryDiagnoseExecutorConformance(Context, nominal, proto);
61076107
} else if (NoncopyableGenerics
61086108
&& proto->isSpecificProtocol(KnownProtocolKind::Copyable)) {
6109-
checkCopyableConformance(conformance);
6109+
checkCopyableConformance(dc, conformance);
61106110
} else if (NoncopyableGenerics
61116111
&& proto->isSpecificProtocol(KnownProtocolKind::Escapable)) {
6112-
checkEscapableConformance(conformance);
6112+
checkEscapableConformance(dc, conformance);
61136113
} else if (Context.LangOpts.hasFeature(Feature::BitwiseCopyable) &&
61146114
proto->isSpecificProtocol(KnownProtocolKind::BitwiseCopyable)) {
61156115
checkBitwiseCopyableConformance(

0 commit comments

Comments
 (0)