mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] Improve handling of invalid protocols during conformance checking
This commit is contained in:
@@ -241,7 +241,7 @@ void NormalProtocolConformance::setTypeWitness(
|
|||||||
assert(getProtocol() == cast<ProtocolDecl>(assocType->getDeclContext()) &&
|
assert(getProtocol() == cast<ProtocolDecl>(assocType->getDeclContext()) &&
|
||||||
"associated type in wrong protocol");
|
"associated type in wrong protocol");
|
||||||
assert(TypeWitnesses.count(assocType) == 0 && "Type witness already known");
|
assert(TypeWitnesses.count(assocType) == 0 && "Type witness already known");
|
||||||
assert(!isComplete() && "Conformance already complete?");
|
assert((!isComplete() || isInvalid()) && "Conformance already complete?");
|
||||||
TypeWitnesses[assocType] = std::make_pair(substitution, typeDecl);
|
TypeWitnesses[assocType] = std::make_pair(substitution, typeDecl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3883,6 +3883,12 @@ checkConformsToProtocol(TypeChecker &TC,
|
|||||||
conformance->setState(ProtocolConformanceState::Checking);
|
conformance->setState(ProtocolConformanceState::Checking);
|
||||||
defer { conformance->setState(ProtocolConformanceState::Complete); };
|
defer { conformance->setState(ProtocolConformanceState::Complete); };
|
||||||
|
|
||||||
|
// If the protocol itself is invalid, there's nothing we can do.
|
||||||
|
if (Proto->isInvalid()) {
|
||||||
|
conformance->setInvalid();
|
||||||
|
return conformance;
|
||||||
|
}
|
||||||
|
|
||||||
// If the protocol requires a class, non-classes are a non-starter.
|
// If the protocol requires a class, non-classes are a non-starter.
|
||||||
if (Proto->requiresClass() && !canT->getClassOrBoundGenericClass()) {
|
if (Proto->requiresClass() && !canT->getClassOrBoundGenericClass()) {
|
||||||
TC.diagnose(ComplainLoc, diag::non_class_cannot_conform_to_class_protocol,
|
TC.diagnose(ComplainLoc, diag::non_class_cannot_conform_to_class_protocol,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// RUN: not --crash %target-swift-frontend %s -parse
|
// RUN: not %target-swift-frontend %s -parse
|
||||||
|
|
||||||
// Distributed under the terms of the MIT license
|
// Distributed under the terms of the MIT license
|
||||||
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// RUN: not --crash %target-swift-frontend %s -parse
|
// RUN: not %target-swift-frontend %s -parse
|
||||||
|
|
||||||
// Distributed under the terms of the MIT license
|
// Distributed under the terms of the MIT license
|
||||||
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// RUN: not --crash %target-swift-frontend %s -parse
|
// RUN: not %target-swift-frontend %s -parse
|
||||||
|
|
||||||
// Distributed under the terms of the MIT license
|
// Distributed under the terms of the MIT license
|
||||||
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// RUN: not --crash %target-swift-frontend %s -parse
|
// RUN: not %target-swift-frontend %s -parse
|
||||||
|
|
||||||
// Distributed under the terms of the MIT license
|
// Distributed under the terms of the MIT license
|
||||||
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
// Test case submitted to project by https://github.com/practicalswift (practicalswift)
|
||||||
Reference in New Issue
Block a user