Skip to content

Commit 0bdacfb

Browse files
authored
Merge pull request #64786 from calda/cal--64757
[SE-0365] Fix #64757: Unexpected "Implicit use of 'self' in closure" error in closure nested in result builder
2 parents f1892fc + 7c78ad2 commit 0bdacfb

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20152015
DC = DC->getParent();
20162016
}
20172017
}
2018+
20182019
const_cast<Expr *>(E)->walk(DiagnoseWalker(ctx, ACE));
20192020
}
20202021

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ void typeCheckASTNode(ASTNode &node, DeclContext *DC,
461461
/// value if an error occurred while type checking the transformed body.
462462
Optional<BraceStmt *> applyResultBuilderBodyTransform(
463463
FuncDecl *func, Type builderType,
464-
bool ClosuresInResultBuilderDontParticipateInInference = true);
464+
bool ClosuresInResultBuilderDontParticipateInInference = false);
465465

466466
/// Find the return statements within the body of the given function.
467467
std::vector<ReturnStmt *> findReturnStatements(AnyFunctionRef fn);

test/expr/closure/closures.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,3 +891,34 @@ func test60781() -> Int {
891891
func test60781_MultiArg() -> Int {
892892
f60781({ 1 }, { 1 }) // expected-error{{conflicting arguments to generic parameter 'T' ('Int' vs. '() -> Int')}}
893893
}
894+
895+
@resultBuilder
896+
struct VoidBuilder {
897+
static func buildBlock() -> Void { }
898+
static func buildPartialBlock<T>(first: T) -> Void { }
899+
static func buildPartialBlock<T>(accumulated: Void, next: T) -> Void { }
900+
}
901+
902+
final class EscapingWrapper {
903+
static func wrapper(_ closure: @escaping () -> Void) {
904+
closure()
905+
}
906+
}
907+
908+
final class TestGithubIssue64757 {
909+
var instanceProperty: String = "instance property"
910+
911+
@VoidBuilder
912+
var void: Void {
913+
EscapingWrapper.wrapper { [weak self] in
914+
print(instanceProperty) // expected-error {{reference to property 'instanceProperty' in closure requires explicit use of 'self' to make capture semantics explicit}}
915+
916+
if let self {
917+
print(instanceProperty)
918+
}
919+
920+
guard let self else { return }
921+
print(instanceProperty)
922+
}
923+
}
924+
}

0 commit comments

Comments
 (0)