Skip to content

Commit 8cc8c5c

Browse files
committed
[Sema] Improve handling of invalid protocols during conformance checking
1 parent 25a9990 commit 8cc8c5c

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void NormalProtocolConformance::setTypeWitness(
241241
assert(getProtocol() == cast<ProtocolDecl>(assocType->getDeclContext()) &&
242242
"associated type in wrong protocol");
243243
assert(TypeWitnesses.count(assocType) == 0 && "Type witness already known");
244-
assert(!isComplete() && "Conformance already complete?");
244+
assert((!isComplete() || isInvalid()) && "Conformance already complete?");
245245
TypeWitnesses[assocType] = std::make_pair(substitution, typeDecl);
246246
}
247247

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,6 +3883,12 @@ checkConformsToProtocol(TypeChecker &TC,
38833883
conformance->setState(ProtocolConformanceState::Checking);
38843884
defer { conformance->setState(ProtocolConformanceState::Complete); };
38853885

3886+
// If the protocol itself is invalid, there's nothing we can do.
3887+
if (Proto->isInvalid()) {
3888+
conformance->setInvalid();
3889+
return conformance;
3890+
}
3891+
38863892
// If the protocol requires a class, non-classes are a non-starter.
38873893
if (Proto->requiresClass() && !canT->getClassOrBoundGenericClass()) {
38883894
TC.diagnose(ComplainLoc, diag::non_class_cannot_conform_to_class_protocol,

validation-test/compiler_crashers/25458-swift-archetypetype-getnestedtype.swift renamed to validation-test/compiler_crashers_fixed/25458-swift-archetypetype-getnestedtype.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27203-swift-typeloc-iserror.swift renamed to validation-test/compiler_crashers_fixed/27203-swift-typeloc-iserror.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27443-matchwitness.swift renamed to validation-test/compiler_crashers_fixed/27443-matchwitness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27742-matchwitness.swift renamed to validation-test/compiler_crashers_fixed/27742-matchwitness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

0 commit comments

Comments
 (0)