Skip to content

Commit 09087cc

Browse files
committed
Sema: Diagnose retroactive conditional conformances
Passing in the declared interface type to checkConformance() here masked a silent failure where if the type declaration was generic and the conformance conditional, the conditional requirement check would fail. As a result, we did not diagnose the absence of @retroactive, nor the unnecessary presence of it. Since we only care about the existence of some conformance, we can use lookupConformance() instead.
1 parent 0f072b4 commit 09087cc

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ static void diagnoseRetroactiveConformances(
16531653
proto->walkInheritedProtocols([&](ProtocolDecl *decl) {
16541654

16551655
// Get the original conformance of the extended type to this protocol.
1656-
auto conformanceRef = ext->getParentModule()->checkConformance(
1656+
auto conformanceRef = ext->getParentModule()->lookupConformance(
16571657
extendedType, decl);
16581658
if (!conformanceRef.isConcrete()) {
16591659

test/IRGen/bitwise-copyable-derived-loadRaw.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public protocol MyBitwiseCopyable : _BitwiseCopyable {}
88

9-
extension SIMD16 : @retroactive MyBitwiseCopyable where Scalar.SIMD16Storage : MyBitwiseCopyable {}
9+
extension SIMD16 : MyBitwiseCopyable where Scalar.SIMD16Storage : MyBitwiseCopyable {}
1010
extension UInt8.SIMD16Storage : MyBitwiseCopyable {}
1111

1212
func doit() {

test/Sema/extension_retroactive_conformances.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public struct Sample5 {}
1515
public struct Sample6 {}
1616

1717
public struct SampleAlreadyConforms: SampleProtocol1 {}
18+
19+
public struct GenericSample1<T> {}
20+
1821
#else
1922

2023
import Library
@@ -81,4 +84,9 @@ extension OriginallyDefinedInLibrary: SampleProtocol1 {} // ok, @_originallyDefi
8184

8285
#endif
8386

87+
// conditional conformances
88+
extension GenericSample1: SampleProtocol1 where T: SampleProtocol1 {}
89+
// expected-warning@-1 {{extension declares a conformance of imported type 'GenericSample1' to imported protocol 'SampleProtocol1'; this will not behave correctly if the owners of 'Library' introduce this conformance in the future}}
90+
// expected-note@-2 {{add '@retroactive' to silence this warning}}
91+
8492
#endif
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2-
extension SIMD2: AdditiveArithmetic where Scalar: FloatingPoint { }
3-
extension SIMD3: AdditiveArithmetic where Scalar: FloatingPoint { }
4-
extension SIMD4: AdditiveArithmetic where Scalar: FloatingPoint { }
5-
extension SIMD8: AdditiveArithmetic where Scalar: FloatingPoint { }
2+
extension SIMD2: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }
3+
extension SIMD3: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }
4+
extension SIMD4: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }
5+
extension SIMD8: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }

0 commit comments

Comments
 (0)