Skip to content

Commit f781b71

Browse files
committed
[Type checker] Produce diagnostics for each of the evaluator requests.
We were suppressing diagnostics for some request kinds; we shouldn't do that.
1 parent 17f42aa commit f781b71

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

include/swift/Sema/TypeCheckRequests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class InheritedTypeRequest :
5858
public:
5959
// Cycle handling
6060
Type breakCycle() const { return Type(); }
61-
void diagnoseCycle(DiagnosticEngine &diags) const { }
62-
void noteCycleStep(DiagnosticEngine &diags) const { }
61+
void diagnoseCycle(DiagnosticEngine &diags) const;
62+
void noteCycleStep(DiagnosticEngine &diags) const;
6363

6464
// Caching
6565
bool isCached() const { return true; }

lib/Sema/TypeCheckRequests.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ Type InheritedTypeRequest::operator()(
117117
return inheritedType ? inheritedType : ErrorType::get(tc.Context);
118118
}
119119

120+
void InheritedTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
121+
const auto &storage = getStorage();
122+
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
123+
diags.diagnose(typeLoc.getLoc(), diag::circular_reference);
124+
}
125+
126+
void InheritedTypeRequest::noteCycleStep(DiagnosticEngine &diags) const {
127+
const auto &storage = getStorage();
128+
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
129+
diags.diagnose(typeLoc.getLoc(), diag::circular_reference_through);
130+
}
131+
120132
Optional<Type> InheritedTypeRequest::getCachedResult() const {
121133
const auto &storage = getStorage();
122134
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
@@ -218,15 +230,15 @@ Type EnumRawTypeRequest::operator()(Evaluator &evaluator,
218230

219231
void EnumRawTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
220232
// FIXME: Improve this diagnostic.
221-
auto classDecl = std::get<0>(getStorage());
222-
std::string className = "'" + std::string(classDecl->getNameStr()) + "'";
223-
diags.diagnose(classDecl, diag::circular_class_inheritance, className);
233+
auto enumDecl = std::get<0>(getStorage());
234+
std::string className = "'" + std::string(enumDecl->getNameStr()) + "'";
235+
diags.diagnose(enumDecl, diag::circular_enum_inheritance, className);
224236
}
225237

226238
void EnumRawTypeRequest::noteCycleStep(DiagnosticEngine &diags) const {
227-
auto classDecl = std::get<0>(getStorage());
239+
auto enumDecl = std::get<0>(getStorage());
228240
// FIXME: Customize this further.
229-
diags.diagnose(classDecl, diag::circular_reference_through);
241+
diags.diagnose(enumDecl, diag::circular_reference_through);
230242
}
231243

232244
Optional<Type> EnumRawTypeRequest::getCachedResult() const {

test/decl/class/circular_inheritance.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,27 @@ class Automorphism : Automorphism { } // expected-error{{circular class inherita
1414
let _ = A() // expected-error{{'A' cannot be constructed because it has no accessible initializers}}
1515

1616
// FIXME: Not technically a circular dependency.
17-
class Left : Right.Hand { // expected-error{{circular class inheritance 'Left'}}
17+
class Left // expected-error{{circular class inheritance 'Left'}}
18+
: Right.Hand { // expected-note{{through reference here}}
1819
class Hand {}
1920
}
2021

21-
class Right : Left.Hand { // expected-note{{through reference here}}
22+
class Right // expected-note{{through reference here}}
23+
: Left.Hand { // expected-note{{through reference here}}
2224
class Hand {}
2325
}
2426

2527
class Outer {
2628
class Inner : Outer {}
2729
}
2830

29-
class Outer2 : Outer2.Inner { // expected-error{{circular class inheritance 'Outer2'}}
31+
class Outer2 // expected-error{{circular class inheritance 'Outer2'}}
32+
: Outer2.Inner { // expected-note{{through reference here}}
33+
3034
class Inner {}
3135
}
3236

33-
class Outer3 : Outer3.Inner<Int> { // expected-error{{circular class inheritance 'Outer3'}}
37+
class Outer3 // expected-error{{circular class inheritance 'Outer3'}}
38+
: Outer3.Inner<Int> { // expected-note{{through reference here}}
3439
class Inner<T> {}
3540
}

0 commit comments

Comments
 (0)