Skip to content

Commit 7c6bbff

Browse files
authored
Merge pull request #63587 from apple/revert-63505-issue-63455
Revert "[CSGen] Handle recursive use of variable declarations"
2 parents c67e298 + bffb8d9 commit 7c6bbff

File tree

4 files changed

+10
-58
lines changed

4 files changed

+10
-58
lines changed

lib/Sema/CSGen.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,33 +1354,20 @@ namespace {
13541354
Type visitDeclRefExpr(DeclRefExpr *E) {
13551355
auto locator = CS.getConstraintLocator(E);
13561356

1357-
auto invalidateReference = [&]() -> Type {
1358-
auto *hole = CS.createTypeVariable(locator, TVO_CanBindToHole);
1359-
(void)CS.recordFix(AllowRefToInvalidDecl::create(CS, locator));
1360-
CS.setType(E, hole);
1361-
return hole;
1362-
};
1363-
13641357
Type knownType;
13651358
if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
13661359
knownType = CS.getTypeIfAvailable(VD);
13671360
if (!knownType)
13681361
knownType = CS.getVarType(VD);
13691362

13701363
if (knownType) {
1371-
// An out-of-scope type variable could be a type of a declaration
1372-
// only in diagnostic mode when invalid variable declaration is
1373-
// recursively referenced inside of a multi-statement closure
1374-
// located somewhere within its initializer e.g.:
1375-
// `let x = [<call>] { ... print(x) }`
1376-
if (auto *typeVar = knownType->getAs<TypeVariableType>()) {
1377-
if (!CS.isActiveTypeVariable(typeVar))
1378-
return invalidateReference();
1379-
}
1380-
13811364
// If the known type has an error, bail out.
13821365
if (knownType->hasError()) {
1383-
return invalidateReference();
1366+
auto *hole = CS.createTypeVariable(locator, TVO_CanBindToHole);
1367+
(void)CS.recordFix(AllowRefToInvalidDecl::create(CS, locator));
1368+
if (!CS.hasType(E))
1369+
CS.setType(E, hole);
1370+
return hole;
13841371
}
13851372

13861373
if (!knownType->hasPlaceholder()) {
@@ -1397,7 +1384,10 @@ namespace {
13971384
// (in getTypeOfReference) so we can match non-error param types.
13981385
if (!knownType && E->getDecl()->isInvalid() &&
13991386
!CS.isForCodeCompletion()) {
1400-
return invalidateReference();
1387+
auto *hole = CS.createTypeVariable(locator, TVO_CanBindToHole);
1388+
(void)CS.recordFix(AllowRefToInvalidDecl::create(CS, locator));
1389+
CS.setType(E, hole);
1390+
return hole;
14011391
}
14021392

14031393
// Create an overload choice referencing this declaration and immediately

lib/Sema/CSSyntacticElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class TypeVariableRefFinder : public ASTWalker {
7474
if (auto *DRE = dyn_cast<DeclRefExpr>(expr)) {
7575
auto *decl = DRE->getDecl();
7676

77-
if (auto type = CS.getTypeIfAvailable(decl)) {
77+
if (auto type = CS.getTypeIfAvailable(DRE->getDecl())) {
7878
auto &ctx = CS.getASTContext();
7979
// If this is not one of the closure parameters which
8080
// is inferrable from the body, let's replace type

test/expr/closure/multi_statement.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -650,16 +650,3 @@ func test_that_closures_are_attempted_in_order() {
650650
return false
651651
}
652652
}
653-
654-
// https://github.com/apple/swift/issues/63455
655-
func test_recursive_var_reference_in_multistatement_closure() {
656-
func takeClosure(_ x: () -> Void) {}
657-
658-
func test(optionalInt: Int?) {
659-
takeClosure {
660-
let int = optionalInt { // expected-error {{cannot call value of non-function type 'Int?'}}
661-
print(int)
662-
}
663-
}
664-
}
665-
}

validation-test/IDE/crashers_2_fixed/issue-63455.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)