Skip to content

Commit 7fccd25

Browse files
authored
Merge pull request #42043 from slavapestov/rqm-diagnostics-request-cycle
RequirementMachine: Fix request evaluator cycle if a typealias requirement becomes redundant
2 parents 0045840 + b859ac1 commit 7fccd25

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static bool isInterestingTypealias(Type type) {
480480
else
481481
return false;
482482

483-
if (aliasDecl->getUnderlyingType()->isVoid())
483+
if (type->isVoid())
484484
return false;
485485

486486
// The 'Swift.AnyObject' typealias is not 'interesting'.

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,13 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
712712
if (assocTypes.contains(typeAliasDecl->getName()))
713713
continue;
714714

715+
// The structural type of a typealias will always be a TypeAliasType,
716+
// so unwrap it to avoid a requirement that prints as 'Self.T == Self.T'
717+
// in diagnostics.
715718
auto underlyingType = typeAliasDecl->getStructuralType();
719+
if (auto *aliasType = dyn_cast<TypeAliasType>(underlyingType.getPointer()))
720+
underlyingType = aliasType->getSinglyDesugaredType();
721+
716722
if (underlyingType->is<UnboundGenericType>())
717723
continue;
718724

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on
2+
3+
protocol P : Sequence {
4+
typealias Element = Iterator.Element
5+
// expected-warning@-1 {{typealias overriding associated type 'Element' from protocol 'Sequence' is better expressed as same-type constraint on the protocol}}
6+
// expected-warning@-2 {{redundant same-type constraint 'Self.Element' == 'Self.Iterator.Element'}}
7+
}

0 commit comments

Comments
 (0)