Skip to content

Commit d8393bc

Browse files
committed
AST: Add Requirement::hasError() utility method
1 parent 541f772 commit d8393bc

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

include/swift/AST/Requirement.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ class Requirement
4242
Requirement(RequirementKind kind, Type first, LayoutConstraint second)
4343
: RequirementBase(kind, first, second) {}
4444

45-
/// Whether this requirement is in its canonical form.
45+
/// Whether this requirement's types contain ErrorTypes.
46+
bool hasError() const;
47+
48+
/// Whether this requirement is written with canonical types.
4649
bool isCanonical() const;
4750

48-
/// Get the canonical form of this requirement.
51+
/// Canonicalize the types in this requirement.
4952
Requirement getCanonical() const;
5053

5154
/// Subst the types involved in this requirement.

lib/AST/GenericSignature.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,26 @@ void swift::simple_display(raw_ostream &out, GenericSignature sig) {
591591
out << "NULL";
592592
}
593593

594+
bool Requirement::hasError() const {
595+
if (getFirstType()->hasError())
596+
return true;
597+
598+
if (getKind() != RequirementKind::Layout &&
599+
getSecondType()->hasError())
600+
return true;
601+
602+
return false;
603+
}
604+
594605
bool Requirement::isCanonical() const {
595-
if (getFirstType() && !getFirstType()->isCanonical())
606+
if (!getFirstType()->isCanonical())
596607
return false;
597608

598609
switch (getKind()) {
599610
case RequirementKind::Conformance:
600611
case RequirementKind::SameType:
601612
case RequirementKind::Superclass:
602-
if (getSecondType() && !getSecondType()->isCanonical())
613+
if (!getSecondType()->isCanonical())
603614
return false;
604615
break;
605616

@@ -612,17 +623,13 @@ bool Requirement::isCanonical() const {
612623

613624
/// Get the canonical form of this requirement.
614625
Requirement Requirement::getCanonical() const {
615-
Type firstType = getFirstType();
616-
if (firstType)
617-
firstType = firstType->getCanonicalType();
626+
Type firstType = getFirstType()->getCanonicalType();
618627

619628
switch (getKind()) {
620629
case RequirementKind::Conformance:
621630
case RequirementKind::SameType:
622631
case RequirementKind::Superclass: {
623-
Type secondType = getSecondType();
624-
if (secondType)
625-
secondType = secondType->getCanonicalType();
632+
Type secondType = getSecondType()->getCanonicalType();
626633
return Requirement(getKind(), firstType, secondType);
627634
}
628635

0 commit comments

Comments
 (0)