Skip to content

Commit 04a91fe

Browse files
committed
[RequirementMachine] Suppress requirement diagnostics when one of the
types already has an error.
1 parent d5814ae commit 04a91fe

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ bool swift::rewriting::diagnoseRequirementErrors(
561561
Type subjectType = error.requirement.getFirstType();
562562
Type constraint = error.requirement.getSecondType();
563563

564+
if (subjectType->hasError() || constraint->hasError())
565+
break;
566+
564567
// FIXME: The constraint string is printed directly here because
565568
// the current default is to not print `any` for existential
566569
// types, but this error message is super confusing without `any`
@@ -608,8 +611,12 @@ bool swift::rewriting::diagnoseRequirementErrors(
608611
}
609612

610613
case RequirementError::Kind::ConflictingRequirement: {
614+
auto subjectType = error.requirement.getFirstType();
615+
if (subjectType->hasError())
616+
break;
617+
611618
ctx.Diags.diagnose(loc, diag::requires_not_suitable_archetype,
612-
error.requirement.getFirstType());
619+
subjectType);
613620
diagnosedError = true;
614621
break;
615622
}

test/Generics/requirement_machine_diagnostics.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ protocol InvalidProtocolWhereClause where Self: Int {}
7878

7979
typealias Alias<T> = T where Int == Int
8080
// expected-warning@-1 {{redundant same-type constraint 'Int' == 'Int'}}
81+
82+
func cascadingConflictingRequirement<T>(_: T) where DoesNotExist : EqualComparable { }
83+
// expected-error@-1 {{cannot find type 'DoesNotExist' in scope}}
84+
85+
func cascadingInvalidConformance<T>(_: T) where T : DoesNotExist { }
86+
// expected-error@-1 {{cannot find type 'DoesNotExist' in scope}}

0 commit comments

Comments
 (0)