Skip to content

Commit 3d9ce27

Browse files
authored
Merge pull request #62161 from angela-laar/some-elision-circular-ref
[AST] Fix circular reference with implicit some
2 parents 6f716a5 + 3b8cfca commit 3d9ce27

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,9 @@ class ValueDecl : public Decl {
27672767
/// some Q), or we might have a `NamedOpaqueReturnTypeRepr`.
27682768
TypeRepr *getOpaqueResultTypeRepr() const;
27692769

2770+
/// Get the representative for this value's result type, if it has one.
2771+
TypeRepr *getResultTypeRepr() const;
2772+
27702773
/// Retrieve the attribute associating this declaration with a
27712774
/// result builder, if there is one.
27722775
CustomAttr *getAttachedResultBuilder() const;

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ namespace {
893893
/// Retrieve the opaque generic parameter list if present, otherwise the normal generic parameter list.
894894
template<typename T>
895895
GenericParamList *getPotentiallyOpaqueGenericParams(T *decl) {
896-
if (auto opaqueRepr = decl->getOpaqueResultTypeRepr()) {
896+
if (auto opaqueRepr = decl->getResultTypeRepr()) {
897897
if (auto namedOpaque = dyn_cast<NamedOpaqueReturnTypeRepr>(opaqueRepr)) {
898898
return namedOpaque->getGenericParams();
899899
}

lib/AST/Decl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,8 @@ void ValueDecl::setOverriddenDecls(ArrayRef<ValueDecl *> overridden) {
30583058
request.cacheResult(overriddenVec);
30593059
}
30603060

3061-
TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
3061+
// To-Do: Replce calls to getOpaqueResultTypeRepr with getResultTypeRepr()
3062+
TypeRepr *ValueDecl::getResultTypeRepr() const {
30623063
TypeRepr *returnRepr = nullptr;
30633064
if (auto *VD = dyn_cast<VarDecl>(this)) {
30643065
if (auto *P = VD->getParentPattern()) {
@@ -3069,7 +3070,7 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
30693070
P = P->getSemanticsProvidingPattern();
30703071
if (auto *NP = dyn_cast<NamedPattern>(P)) {
30713072
assert(NP->getDecl() == VD);
3072-
(void) NP;
3073+
(void)NP;
30733074

30743075
returnRepr = TP->getTypeRepr();
30753076
}
@@ -3083,6 +3084,12 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
30833084
returnRepr = SD->getElementTypeRepr();
30843085
}
30853086

3087+
return returnRepr;
3088+
}
3089+
3090+
TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
3091+
auto *returnRepr = this->getResultTypeRepr();
3092+
30863093
auto *dc = getDeclContext();
30873094
auto &ctx = dc->getASTContext();
30883095

test/type/implicit_some/opaque_return.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ struct S: P {
115115

116116
var asExistential: any P { self }
117117
}
118+
119+
enum E {
120+
func f() -> Int {
121+
1
122+
}
123+
}
124+
125+
protocol Q {
126+
func f() -> Int
127+
}

0 commit comments

Comments
 (0)