Skip to content

Commit a8a281d

Browse files
committed
RequirementMachine: Use recordConflict() for superclass conflicts
Instead of calling markConflicting() directly, use the existing recordConflict() utility.
1 parent 6d2ebb3 commit a8a281d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ void PropertyMap::recordSuperclassRelation(Term key,
228228
void PropertyMap::addSuperclassProperty(
229229
Term key, Symbol property, unsigned ruleID) {
230230
auto *props = getOrCreateProperties(key);
231-
auto &newRule = System.getRule(ruleID);
232231
bool debug = Debug.contains(DebugFlags::ConcreteUnification);
233232

234233
const auto *superclassDecl = property.getConcreteType()
@@ -345,8 +344,9 @@ void PropertyMap::addSuperclassProperty(
345344
<< props->SuperclassDecl->getName() << "\n";
346345
}
347346

348-
// FIXME: Record the conflict better
349-
newRule.markConflicting();
347+
auto &req = props->Superclasses[props->SuperclassDecl];
348+
for (const auto &pair : req.SuperclassRules)
349+
System.recordConflict(pair.second, ruleID);
350350
}
351351
}
352352

test/Generics/superclass_and_concrete_requirement.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
1+
// RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=verify
2+
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-protocol-signatures=verify -requirement-machine-inferred-signatures=verify 2>&1 | %FileCheck %s
23

34
class C {}
45

@@ -8,18 +9,26 @@ struct S {}
89
// CHECK-NEXT: Requirement signature: <Self where Self.[P1]T == C>
910
protocol P1 {
1011
associatedtype T where T : C, T == C
12+
// expected-warning@-1 {{redundant superclass constraint 'Self.T' : 'C'}}
13+
// expected-note@-2 {{superclass constraint 'Self.T' : 'C' implied here}}
1114
}
1215

1316
// CHECK-LABEL: .P2@
1417
// CHECK-NEXT: Requirement signature: <Self where Self.[P2]T == S>
1518
protocol P2 {
1619
associatedtype T where T : C, T == S
20+
// expected-error@-1 {{'Self.T' requires that 'S' inherit from 'C'}}
21+
// expected-note@-2 {{superclass constraint 'Self.T' : 'C' implied here}}
22+
// expected-note@-3 {{same-type constraint 'Self.T' == 'S' implied here}}
1723
}
1824

1925
// CHECK-LABEL: .P3@
2026
// CHECK-NEXT: Requirement signature: <Self where Self.[P3]T == S>
2127
protocol P3 {
2228
associatedtype T where T == S, T : C
29+
// expected-error@-1 {{'Self.T' requires that 'S' inherit from 'C'}}
30+
// expected-note@-2 {{same-type constraint 'Self.T' == 'S' implied here}}
31+
// expected-note@-3 {{superclass constraint 'Self.T' : 'C' implied here}}
2332
}
2433

2534
protocol P4a {
@@ -30,4 +39,16 @@ protocol P4a {
3039
// CHECK-NEXT: Requirement signature: <Self where Self.[P4]T : P4>
3140
protocol P4 {
3241
associatedtype T : P4 where T.T == S
42+
// expected-error@-1 2{{same-type constraint type 'S' does not conform to required protocol 'P4'}}
43+
}
44+
45+
class D {}
46+
47+
// CHECK-LABEL: .P5@
48+
// CHECK-NEXT: Requirement signature: <Self where Self.[P5]T == D>
49+
protocol P5 {
50+
associatedtype T where T : C, T == D
51+
// expected-error@-1 {{'Self.T' requires that 'D' inherit from 'C'}}
52+
// expected-note@-2 {{superclass constraint 'Self.T' : 'C' implied here}}
53+
// expected-note@-3 {{same-type constraint 'Self.T' == 'D' implied here}}
3354
}

0 commit comments

Comments
 (0)