Skip to content

Commit

Permalink
Merge pull request #42043 from slavapestov/rqm-diagnostics-request-cycle
Browse files Browse the repository at this point in the history
RequirementMachine: Fix request evaluator cycle if a typealias requirement becomes redundant
  • Loading branch information
slavapestov committed Mar 27, 2022
2 parents 0045840 + b859ac1 commit 7fccd25
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/AST/DiagnosticEngine.cpp
Expand Up @@ -480,7 +480,7 @@ static bool isInterestingTypealias(Type type) {
else
return false;

if (aliasDecl->getUnderlyingType()->isVoid())
if (type->isVoid())
return false;

// The 'Swift.AnyObject' typealias is not 'interesting'.
Expand Down
6 changes: 6 additions & 0 deletions lib/AST/RequirementMachine/RequirementLowering.cpp
Expand Up @@ -712,7 +712,13 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
if (assocTypes.contains(typeAliasDecl->getName()))
continue;

// The structural type of a typealias will always be a TypeAliasType,
// so unwrap it to avoid a requirement that prints as 'Self.T == Self.T'
// in diagnostics.
auto underlyingType = typeAliasDecl->getStructuralType();
if (auto *aliasType = dyn_cast<TypeAliasType>(underlyingType.getPointer()))
underlyingType = aliasType->getSinglyDesugaredType();

if (underlyingType->is<UnboundGenericType>())
continue;

Expand Down
7 changes: 7 additions & 0 deletions test/Generics/protocol_typealias_cycle_5.swift
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on

protocol P : Sequence {
typealias Element = Iterator.Element
// expected-warning@-1 {{typealias overriding associated type 'Element' from protocol 'Sequence' is better expressed as same-type constraint on the protocol}}
// expected-warning@-2 {{redundant same-type constraint 'Self.Element' == 'Self.Iterator.Element'}}
}

0 comments on commit 7fccd25

Please sign in to comment.