@@ -660,6 +660,28 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
660
660
for (unsigned index : indices (lhs)) {
661
661
auto symbol = lhs[index];
662
662
663
+ // The left hand side can contain a single name symbol if it has the form
664
+ // T.N or T.N.[p], where T is some prefix that does not contain name
665
+ // symbols, N is a name symbol, and [p] is an optional property symbol.
666
+ //
667
+ // In the latter case, we have a protocol typealias, or a rule derived
668
+ // via resolving a critical pair involving a protocol typealias.
669
+ //
670
+ // Any other valid occurrence of a name symbol should have been reduced by
671
+ // an associated type introduction rule [P].N, marking the rule as
672
+ // LHS-simplified.
673
+ if (!rule.isLHSSimplified () &&
674
+ (rule.isPropertyRule ()
675
+ ? index != lhs.size () - 2
676
+ : index != lhs.size () - 1 )) {
677
+ // This is only true if the input requirements were valid.
678
+ if (policy == DisallowInvalidRequirements) {
679
+ ASSERT_RULE (symbol.getKind () != Symbol::Kind::Name);
680
+ } else {
681
+ // FIXME: Assert that we diagnosed an error
682
+ }
683
+ }
684
+
663
685
if (index != lhs.size () - 1 ) {
664
686
ASSERT_RULE (symbol.getKind () != Symbol::Kind::Layout);
665
687
ASSERT_RULE (!symbol.hasSubstitutions ());
@@ -677,14 +699,18 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
677
699
for (unsigned index : indices (rhs)) {
678
700
auto symbol = rhs[index];
679
701
680
- // RHS-simplified rules might have unresolved name symbols on the
681
- // right hand side. Also, completion can introduce rules of the
682
- // form T.X.[concrete: C] => T.X, where T is some resolved term,
683
- // and X is a name symbol for a protocol typealias.
684
- if (!rule.isLHSSimplified () &&
685
- !rule.isRHSSimplified () &&
686
- !(rule.isPropertyRule () &&
687
- index == rhs.size () - 1 )) {
702
+ // The right hand side can contain a single name symbol if it has the form
703
+ // T.N, where T is some prefix that does not contain name symbols, and
704
+ // N is a name symbol.
705
+ //
706
+ // In this case, we have a protocol typealias, or a rule derived via
707
+ // resolving a critical pair involving a protocol typealias.
708
+ //
709
+ // Any other valid occurrence of a name symbol should have been reduced by
710
+ // an associated type introduction rule [P].N, marking the rule as
711
+ // RHS-simplified.
712
+ if (!rule.isRHSSimplified () &&
713
+ index != rhs.size () - 1 ) {
688
714
// This is only true if the input requirements were valid.
689
715
if (policy == DisallowInvalidRequirements) {
690
716
ASSERT_RULE (symbol.getKind () != Symbol::Kind::Name);
0 commit comments