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.
This commit is contained in:
Slava Pestov
2024-01-16 15:51:57 -05:00
parent 0f072b4803
commit 09087ccce8
4 changed files with 14 additions and 6 deletions

View File

@@ -1653,7 +1653,7 @@ static void diagnoseRetroactiveConformances(
proto->walkInheritedProtocols([&](ProtocolDecl *decl) {
// Get the original conformance of the extended type to this protocol.
auto conformanceRef = ext->getParentModule()->checkConformance(
auto conformanceRef = ext->getParentModule()->lookupConformance(
extendedType, decl);
if (!conformanceRef.isConcrete()) {

View File

@@ -6,7 +6,7 @@
public protocol MyBitwiseCopyable : _BitwiseCopyable {}
extension SIMD16 : @retroactive MyBitwiseCopyable where Scalar.SIMD16Storage : MyBitwiseCopyable {}
extension SIMD16 : MyBitwiseCopyable where Scalar.SIMD16Storage : MyBitwiseCopyable {}
extension UInt8.SIMD16Storage : MyBitwiseCopyable {}
func doit() {

View File

@@ -15,6 +15,9 @@ public struct Sample5 {}
public struct Sample6 {}
public struct SampleAlreadyConforms: SampleProtocol1 {}
public struct GenericSample1<T> {}
#else
import Library
@@ -81,4 +84,9 @@ extension OriginallyDefinedInLibrary: SampleProtocol1 {} // ok, @_originallyDefi
#endif
// conditional conformances
extension GenericSample1: SampleProtocol1 where T: SampleProtocol1 {}
// 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}}
// expected-note@-2 {{add '@retroactive' to silence this warning}}
#endif

View File

@@ -1,5 +1,5 @@
// RUN: %target-typecheck-verify-swift
extension SIMD2: AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD3: AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD4: AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD8: AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD2: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD3: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD4: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }
extension SIMD8: @retroactive AdditiveArithmetic where Scalar: FloatingPoint { }