From 42277cfbbb4ca3ffe7864d33598fb34437f051a5 Mon Sep 17 00:00:00 2001 From: Holly Borla Date: Tue, 23 Jul 2024 14:05:21 -0700 Subject: [PATCH 1/2] [Conformance] Always downgrade redundant conformances to marker protocols to a warning. Previous compiler versions allowed this, so we should stage the change in as a warning. This was already a warning across modules, so this change only impacts redundant conformances to marker protocols within a module. This code also isn't particularly harmful, because marker protocols don't have requirements, so there isn't the same risk of unexpected behavior as other redundant conformances. (cherry picked from commit 5eb16ad3dee182f2e58a8ac81442542901e81e7c) --- lib/Sema/TypeCheckProtocol.cpp | 2 +- test/decl/protocol/conforms/redundant_conformance.swift | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index 299b6848ee053..e4db09c1a2142 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -6283,7 +6283,7 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) { } if ((existingModule != dc->getParentModule() && conformanceInOrigModule) || - isSendable) { + diag.Protocol->isMarkerProtocol()) { // Warn about the conformance. if (isSendable && SendableConformance && isa(SendableConformance)) { diff --git a/test/decl/protocol/conforms/redundant_conformance.swift b/test/decl/protocol/conforms/redundant_conformance.swift index 0568637c8e173..41d8b1953f376 100644 --- a/test/decl/protocol/conforms/redundant_conformance.swift +++ b/test/decl/protocol/conforms/redundant_conformance.swift @@ -86,3 +86,10 @@ class Class3 { class SomeMockClass: Class3.ProviderThree { // okay var someInt: Int = 5 } + + +class ImplicitCopyable {} + +class InheritImplicitCopyable: ImplicitCopyable, Copyable {} +// expected-warning@-1 {{redundant conformance of 'InheritImplicitCopyable' to protocol 'Copyable'}} +// expected-note@-2 {{'InheritImplicitCopyable' inherits conformance to protocol 'Copyable' from superclass here}} From 39345fee0eebeb844b625d4bd8e2049f43f71b6f Mon Sep 17 00:00:00 2001 From: Holly Borla Date: Tue, 23 Jul 2024 16:50:35 -0700 Subject: [PATCH 2/2] [NFC][Copyable] Update an expected error to a warning. (cherry picked from commit 286bdeb481d754941a73d2a79b89b6e1bce7517d) --- test/Parse/inverses.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Parse/inverses.swift b/test/Parse/inverses.swift index bdd26e64bbfdf..ae8b8f87480a7 100644 --- a/test/Parse/inverses.swift +++ b/test/Parse/inverses.swift @@ -143,7 +143,7 @@ struct Burrito: ~Copyable {} extension Burrito: Alias {} // expected-error {{conformance to 'Copyable' must be declared in a separate extension}} // expected-note@-1 {{'Burrito' declares conformance to protocol 'Copyable' here}} -extension Burrito: Copyable & Edible & P {} // expected-error {{redundant conformance of 'Burrito' to protocol 'Copyable'}} +extension Burrito: Copyable & Edible & P {} // expected-warning {{redundant conformance of 'Burrito' to protocol 'Copyable'}} struct Blah: ~Copyable {} extension Blah: P, Q, Copyable, R {} // expected-error {{generic struct 'Blah' required to be 'Copyable' but is marked with '~Copyable'}}