Skip to content

Commit 13816fa

Browse files
authored
Merge pull request #85159 from tshortli/suppress-inherited-retroactive-conformance-diags-with-module-qualification-6.2
[6.2] Sema: Fix a regression in retroactive conformance diagnostic suppression
2 parents 8c1cc1b + 60c711d commit 13816fa

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,17 +1864,16 @@ static void diagnoseRetroactiveConformances(
18641864
continue;
18651865
}
18661866

1867+
bool isMarkedRetroactive = entry.isRetroactive();
18671868
SmallVector<ProtocolDecl *, 2> protos;
18681869
if (auto *protoTy = inheritedTy->getAs<ProtocolType>()) {
18691870
auto *proto = protoTy->getDecl();
18701871

18711872
// As a fallback, to support previous language versions, also allow
18721873
// this through if the protocol has been explicitly module-qualified.
18731874
TypeRepr *repr = unwrapAttributedRepr(entry.getTypeRepr());
1874-
if (isModuleQualified(repr, proto->getParentModule())) {
1875-
protocolsWithRetroactiveAttr.insert(proto);
1876-
continue;
1877-
}
1875+
if (isModuleQualified(repr, proto->getParentModule()))
1876+
isMarkedRetroactive = true;
18781877

18791878
protos.push_back(proto);
18801879
} else if (auto *compositionTy = inheritedTy->getAs<ProtocolCompositionType>()) {
@@ -1920,7 +1919,7 @@ static void diagnoseRetroactiveConformances(
19201919
}
19211920

19221921
// If it's marked @retroactive, no need to warn.
1923-
if (entry.isRetroactive()) {
1922+
if (isMarkedRetroactive) {
19241923
// Note that we encountered this protocol through a conformance marked
19251924
// @retroactive in case multiple clauses cause the protocol to be
19261925
// inherited.

test/Sema/extension_retroactive_conformances.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ public struct Sample3 {}
2020
public struct Sample4 {}
2121
public struct Sample5 {}
2222
public struct Sample6 {}
23+
public struct Sample6a {}
24+
public struct Sample6b {}
25+
public struct Sample6c {}
2326
public struct Sample7 {}
2427
public struct Sample8 {}
28+
public struct Sample8a {}
2529

2630
public struct SampleAlreadyConforms: SampleProtocol1 {}
2731

@@ -76,9 +80,13 @@ typealias MySample6 = Sample6
7680
extension MySample6: SampleProtocol1 {} // expected-warning {{extension declares a conformance of imported type 'Sample6' to imported protocol 'SampleProtocol1'}}
7781
// expected-note @-1 {{add '@retroactive' to silence this warning}} {{22-37=@retroactive SampleProtocol1}}
7882

79-
// Ensure module-qualifying both types still silences the warning
83+
// Ensure module-qualifying the protocol silences the warning
8084

81-
extension Library.Sample6: Library.SampleProtocol2 {} // ok, module-qualified.
85+
extension Library.Sample6: Library.SampleProtocol2 {} // ok, both types are module-qualified.
86+
extension Sample6a: Library.SampleProtocol2 {} // ok, protocol is module qualified.
87+
extension Library.Sample6b: SampleProtocol2 {} // expected-warning {{extension declares a conformance of imported type 'Sample6b' to imported protocol 'SampleProtocol2'; this will not behave correctly if the owners of 'Library' introduce this conformance in the future}}
88+
// expected-note @-1 {{add '@retroactive' to silence this warning}}
89+
extension Sample6c: Library.SampleProtocol1a {} // ok, protocol is module qualified.
8290

8391
protocol ClientProtocol {}
8492

0 commit comments

Comments
 (0)