Skip to content

Commit 9bc2819

Browse files
authored
Merge pull request swiftlang#33590 from xedin/fail-on-error-if-single-stmt
[CSGen] Abort constraint generation on error only if closure part…
2 parents 1fdcdce + 94bf392 commit 9bc2819

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,10 +2775,17 @@ namespace {
27752775
return { true, expr };
27762776
}
27772777
} collectVarRefs(CS);
2778+
27782779
closure->walk(collectVarRefs);
27792780

2780-
if (collectVarRefs.hasErrorExprs)
2781+
// If walker discovered error expressions, let's fail constraint
2782+
// genreation only if closure is going to participate
2783+
// in the type-check. This allows us to delay validation of
2784+
// multi-statement closures until body is opened.
2785+
if (shouldTypeCheckInEnclosingExpression(closure) &&
2786+
collectVarRefs.hasErrorExprs) {
27812787
return Type();
2788+
}
27822789

27832790
auto inferredType = inferClosureType(closure);
27842791
if (!inferredType || inferredType->hasError())

test/expr/closure/closures.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func anonymousClosureArgsInClosureWithArgs() {
141141
var a5 = { (_: [Int], w: [Int]) in
142142
f($0.count) // expected-error {{anonymous closure arguments cannot be used inside a closure that has explicit arguments}}
143143
f($1.count) // expected-error {{anonymous closure arguments cannot be used inside a closure that has explicit arguments; did you mean 'w'?}} {{7-9=w}}
144+
// expected-error@-1 {{cannot convert value of type 'Int' to expected argument type 'String'}}
144145
}
145146
}
146147

0 commit comments

Comments
 (0)