[CSGen] Detect nested out-of-scope variables in recursive declarations

Follow-up to https://github.com/apple/swift/pull/63505

Since, when the type is not stated, a variable assumes the
type of its initializer that enables out-of-scope variables
to be nested inside of some other concrete type i.e. Optional.

Resolves: https://github.com/apple/swift/issues/63455
This commit is contained in:
Pavel Yaskevich
2023-02-10 00:57:02 -08:00
committed by Pavel Yaskevich
parent 0b58685ace
commit 8e82f1d68b
3 changed files with 71 additions and 10 deletions

View File

@@ -74,7 +74,7 @@ public:
if (auto *DRE = dyn_cast<DeclRefExpr>(expr)) {
auto *decl = DRE->getDecl();
if (auto type = CS.getTypeIfAvailable(DRE->getDecl())) {
if (auto type = CS.getTypeIfAvailable(decl)) {
auto &ctx = CS.getASTContext();
// If this is not one of the closure parameters which
// is inferrable from the body, let's replace type