[Sema] Improve handling of invalid protocols during conformance checking

This commit is contained in:
Jacob Bandes-Storch
2016-01-07 22:25:11 -08:00
parent 25a999063c
commit 8cc8c5cc22
6 changed files with 11 additions and 5 deletions

View File

@@ -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);
} }

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)