mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Runtime] Detect and log redundant subclass/superclass conformances.
When we rely on a protocol conformance, and the type in question has multiple conformances to that protocol in its inheritance chain, emit a runtime warning. It's quite tricky to cause this problem - you need a type in one dylib that is extended to conform to a protocol in another dylib, subclassed in another module and then some subclass has protocol conformance added as well. If they're in the same module, the compiler will give an error and prevent the problem completely. rdar://73364629
This commit is contained in:
@@ -906,10 +906,20 @@ swift_conformsToProtocolImpl(const Metadata *const type,
|
||||
const WitnessTable *foundWitness = nullptr;
|
||||
const Metadata *foundType = nullptr;
|
||||
for (auto searchType : iterateMaybeIncompleteSuperclasses(type)) {
|
||||
foundWitness = foundWitnesses.lookup(searchType);
|
||||
if (foundWitness) {
|
||||
foundType = searchType;
|
||||
break;
|
||||
const WitnessTable *witness = foundWitnesses.lookup(searchType);
|
||||
if (witness) {
|
||||
if (!foundType) {
|
||||
foundWitness = witness;
|
||||
foundType = searchType;
|
||||
} else {
|
||||
swift::warning(RuntimeErrorFlagNone,
|
||||
"Warning: '%s' conforms to protocol '%s', but it also "
|
||||
"inherits conformance from '%s'. Relying on a "
|
||||
"particular conformance is undefined behaviour.\n",
|
||||
foundType->getDescription()->Name.get(),
|
||||
protocol->Name.get(),
|
||||
searchType->getDescription()->Name.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user