Skip to content

Commit 63abfab

Browse files
authored
Merge pull request #85738 from hamishknight/to-wit
[Frontend] Enforce an error was emitted for invalid conformance
2 parents ad56e06 + 7b8f112 commit 63abfab

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,13 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
11561156

11571157
// Emit extracted constant values for every file in the batch
11581158
emitConstValuesForAllPrimaryInputsIfNeeded(Instance);
1159+
1160+
// Make sure we emitted an error if we encountered an invalid conformance.
1161+
// This is important since `ASTContext::hadError` accounts for delayed
1162+
// conformance diags, so we need to ensure we don't exit with a non-zero exit
1163+
// code without emitting any error.
1164+
ASSERT(ctx.Diags.hadAnyError() || !ctx.hasDelayedConformanceErrors() &&
1165+
"Encountered invalid conformance without emitting error?");
11591166
}
11601167

11611168
static bool printSwiftVersion(const CompilerInvocation &Invocation) {

lib/Sema/TypeOfReference.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,8 +1496,15 @@ void ConstraintSystem::openGenericRequirement(
14961496
switch (kind) {
14971497
case RequirementKind::Conformance: {
14981498
auto protoDecl = req.getProtocolDecl();
1499-
// Determine whether this is the protocol 'Self' constraint we should
1500-
// skip.
1499+
// Determine whether this is the protocol 'Self' constraint we should skip.
1500+
//
1501+
// NOTE: At first glance it seems like this is just an optimization to avoid
1502+
// adding a redundant constraint, but it is in fact load bearing for
1503+
// DistributedActor since we can form a conformance to Actor in
1504+
// GetDistributedActorAsActorConformanceRequest despite the fact that
1505+
// DistributedActor does not require Actor conformance (although conforming
1506+
// types are guaranteed to have the witnesses). So a conformance check in
1507+
// that case would fail.
15011508
if (skipProtocolSelfConstraint && protoDecl == outerDC &&
15021509
protoDecl->getSelfInterfaceType()->isEqual(req.getFirstType()))
15031510
return;

0 commit comments

Comments
 (0)