Skip to content

Commit 07bd079

Browse files
committed
AST: Implement extractNearestSourceLoc() for ProtocolConformance
1 parent e148032 commit 07bd079

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

include/swift/AST/ProtocolConformance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ inline bool ProtocolConformance::hasWitness(ValueDecl *requirement) const {
10221022
return getRootConformance()->hasWitness(requirement);
10231023
}
10241024

1025+
SourceLoc extractNearestSourceLoc(const ProtocolConformance *conf);
10251026
void simple_display(llvm::raw_ostream &out, const ProtocolConformance *conf);
10261027

10271028
} // end namespace swift

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,10 @@ void swift::simple_display(llvm::raw_ostream &out,
15311531
conf->printName(out);
15321532
}
15331533

1534+
SourceLoc swift::extractNearestSourceLoc(const ProtocolConformance *conformance) {
1535+
return extractNearestSourceLoc(conformance->getDeclContext());
1536+
}
1537+
15341538
void swift::simple_display(llvm::raw_ostream &out, ProtocolConformanceRef conformanceRef) {
15351539
if (conformanceRef.isAbstract()) {
15361540
simple_display(out, conformanceRef.getAbstract());
@@ -1543,7 +1547,7 @@ SourceLoc swift::extractNearestSourceLoc(const ProtocolConformanceRef conformanc
15431547
if (conformanceRef.isAbstract()) {
15441548
return extractNearestSourceLoc(conformanceRef.getAbstract());
15451549
} else if (conformanceRef.isConcrete()) {
1546-
return extractNearestSourceLoc(conformanceRef.getConcrete()->getProtocol());
1550+
return extractNearestSourceLoc(conformanceRef.getConcrete());
15471551
}
15481552
return SourceLoc();
15491553
}

test/decl/circularity.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ extension SIMD3 where SIMD3.Scalar == Float {
6161
protocol P {
6262
associatedtype A
6363
// expected-note@-1 {{protocol requires nested type 'A'; do you want to add it?}}
64-
// expected-note@-2 {{through reference here}}
6564
func run(a: A)
6665
}
6766

@@ -70,6 +69,7 @@ class C1 {
7069
}
7170

7271
class C2: C1, P {
72+
// expected-note@-1 {{through reference here}}
7373
override func run(a: A) {}
7474
// expected-error@-1 {{circular reference}}
7575
// expected-note@-2 {{while resolving type 'A'}}
@@ -90,15 +90,15 @@ class C3: G1<A>, P {
9090

9191
// Another case that triggers circular override checking.
9292
protocol P1 {
93-
associatedtype X = Int // expected-note {{through reference here}}
93+
associatedtype X = Int
9494
init(x: X)
9595
}
9696

9797
class C4 {
9898
required init(x: Int) {}
9999
}
100100

101-
class D4 : C4, P1 { // expected-note 2 {{through reference here}}
101+
class D4 : C4, P1 { // expected-note 3 {{through reference here}}
102102
required init(x: X) { // expected-error {{circular reference}}
103103
// expected-note@-1 {{while resolving type 'X'}}
104104
// expected-note@-2 2{{through reference here}}

0 commit comments

Comments
 (0)