File tree Expand file tree Collapse file tree 3 files changed +21
-13
lines changed Expand file tree Collapse file tree 3 files changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ namespace swift {
90
90
class UnboundGenericType ;
91
91
class ValueDecl ;
92
92
class VarDecl ;
93
+ class OpaqueReturnTypeRepr ;
93
94
94
95
enum class DeclKind : uint8_t {
95
96
#define DECL (Id, Parent ) Id,
@@ -2692,7 +2693,10 @@ class ValueDecl : public Decl {
2692
2693
2693
2694
// / Get the decl for this value's opaque result type, if it has one.
2694
2695
OpaqueTypeDecl *getOpaqueResultTypeDecl () const ;
2695
-
2696
+
2697
+ // / Get the representative for this value's opaque result type, if it has one.
2698
+ OpaqueReturnTypeRepr *getOpaqueResultTypeRepr () const ;
2699
+
2696
2700
// / Set the opaque return type decl for this decl.
2697
2701
// /
2698
2702
// / `this` must be of a decl type that supports opaque return types, and
Original file line number Diff line number Diff line change @@ -2454,6 +2454,19 @@ void ValueDecl::setOverriddenDecls(ArrayRef<ValueDecl *> overridden) {
2454
2454
request.cacheResult (overriddenVec);
2455
2455
}
2456
2456
2457
+ OpaqueReturnTypeRepr *ValueDecl::getOpaqueResultTypeRepr () const {
2458
+ TypeLoc returnLoc;
2459
+ if (auto *VD = dyn_cast<VarDecl>(this )) {
2460
+ returnLoc = VD->getTypeLoc ();
2461
+ } else if (auto *FD = dyn_cast<FuncDecl>(this )) {
2462
+ returnLoc = FD->getBodyResultTypeLoc ();
2463
+ } else if (auto *SD = dyn_cast<SubscriptDecl>(this )) {
2464
+ returnLoc = SD->getElementTypeLoc ();
2465
+ }
2466
+
2467
+ return dyn_cast_or_null<OpaqueReturnTypeRepr>(returnLoc.getTypeRepr ());
2468
+ }
2469
+
2457
2470
OpaqueTypeDecl *ValueDecl::getOpaqueResultTypeDecl () const {
2458
2471
if (auto func = dyn_cast<FuncDecl>(this )) {
2459
2472
return func->getOpaqueResultTypeDecl ();
Original file line number Diff line number Diff line change @@ -278,18 +278,9 @@ bool RequirementFailure::diagnoseAsError() {
278
278
anchor->getLoc (), diag::type_does_not_conform_in_opaque_return,
279
279
namingDecl->getDescriptiveKind (), namingDecl->getFullName (), lhs, rhs);
280
280
281
- TypeLoc returnLoc;
282
- if (auto *VD = dyn_cast<VarDecl>(namingDecl)) {
283
- returnLoc = VD->getTypeLoc ();
284
- } else if (auto *FD = dyn_cast<FuncDecl>(namingDecl)) {
285
- returnLoc = FD->getBodyResultTypeLoc ();
286
- } else if (auto *SD = dyn_cast<SubscriptDecl>(namingDecl)) {
287
- returnLoc = SD->getElementTypeLoc ();
288
- }
289
-
290
- if (returnLoc.hasLocation ()) {
291
- emitDiagnostic (returnLoc.getLoc (), diag::opaque_return_type_declared_here)
292
- .highlight (returnLoc.getSourceRange ());
281
+ if (auto *repr = namingDecl->getOpaqueResultTypeRepr ()) {
282
+ emitDiagnostic (repr->getLoc (), diag::opaque_return_type_declared_here)
283
+ .highlight (repr->getSourceRange ());
293
284
}
294
285
return true ;
295
286
}
You can’t perform that action at this time.
0 commit comments