diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 252c1deb46279..44f3881901be6 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -4926,7 +4926,9 @@ bool MissingArgumentsFailure::diagnoseClosure(const ClosureExpr *closure) { auto *locator = getLocator(); if (locator->isForContextualType()) { - funcType = getContextualType(locator->getAnchor())->getAs(); + if (auto contextualType = getContextualType(locator->getAnchor())) { + funcType = contextualType->getAs(); + } } else if (auto info = getFunctionArgApplyInfo(locator)) { auto paramType = info->getParamType(); // Drop a single layer of optionality because argument could get injected diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 3d80c594b0c52..604dd5faec691 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -2901,18 +2901,12 @@ namespace { struct CollectVarRefs : public ASTWalker { ConstraintSystem &cs; llvm::SmallPtrSet varRefs; - bool hasErrorExprs = false; CollectVarRefs(ConstraintSystem &cs) : cs(cs) { } bool shouldWalkCaptureInitializerExpressions() override { return true; } PreWalkResult walkToExprPre(Expr *expr) override { - // If there are any error expressions in this closure - // it wouldn't be possible to infer its type. - if (isa(expr)) - hasErrorExprs = true; - // Retrieve type variables from references to var decls. if (auto *declRef = dyn_cast(expr)) { if (auto *varDecl = dyn_cast(declRef->getDecl())) { @@ -2954,15 +2948,6 @@ namespace { closure->walk(collectVarRefs); - // If walker discovered error expressions, let's fail constraint - // generation only if closure is going to participate - // in the type-check. This allows us to delay validation of - // multi-statement closures until body is opened. - if (CS.participatesInInference(closure) && - collectVarRefs.hasErrorExprs) { - return Type(); - } - auto inferredType = inferClosureType(closure); if (!inferredType || inferredType->hasError()) return Type(); diff --git a/test/Constraints/result_builder_diags.swift b/test/Constraints/result_builder_diags.swift index ad4cb3f23d47e..aeb34ff1055fb 100644 --- a/test/Constraints/result_builder_diags.swift +++ b/test/Constraints/result_builder_diags.swift @@ -78,7 +78,7 @@ struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf static func buildDo(_ value: T) -> T { return value } } -func tuplify(_ cond: Bool, @TupleBuilder body: (Bool) -> T) { +func tuplify(_ cond: Bool, @TupleBuilder body: (Bool) -> T) { // expected-note 2{{in call to function 'tuplify(_:body:)'}} print(body(cond)) } @@ -88,7 +88,7 @@ func tuplifyWithoutIf(_ cond: Bool, @TupleBuilderWithoutIf body: (Bool) -> T) func testDiags() { // For loop - tuplify(true) { _ in + tuplify(true) { _ in // expected-error {{generic parameter 'T' could not be inferred}} 17 for c in name { // expected-error@-1 {{cannot find 'name' in scope}} @@ -464,7 +464,7 @@ struct TestConstraintGenerationErrors { } func buildTupleClosure() { - tuplify(true) { _ in + tuplify(true) { _ in // expected-error {{generic parameter 'T' could not be inferred}} let a = nothing // expected-error {{cannot find 'nothing' in scope}} String(nothing) // expected-error {{cannot find 'nothing' in scope}} } diff --git a/test/Parse/recovery.swift b/test/Parse/recovery.swift index 3d00746bf6b3f..914b1679448a3 100644 --- a/test/Parse/recovery.swift +++ b/test/Parse/recovery.swift @@ -775,7 +775,7 @@ class r22240342 { lazy var xx: Int = { foo { // expected-error {{cannot find 'foo' in scope}} let issueView = 42 - issueView.delegate = 12 + issueView.delegate = 12 // expected-error {{value of type 'Int' has no member 'delegate'}} } return 42 diff --git a/test/StringProcessing/Sema/regex_builder_fix_import_top_level.swift b/test/StringProcessing/Sema/regex_builder_fix_import_top_level.swift index e3046c82b939d..eaae05546891c 100644 --- a/test/StringProcessing/Sema/regex_builder_fix_import_top_level.swift +++ b/test/StringProcessing/Sema/regex_builder_fix_import_top_level.swift @@ -19,11 +19,7 @@ Regex { // expected-error {{regex builder requires the 'RegexBuilder' module be /g(h)(i)/ } -// FIXME: Unfortunately we bail from CSGen if we end up with an ErrorExpr, so -// don't get a chance to diagnose. We ought to try solving with holes. -// For now at least, this error should at least hopefully nudge users into -// realizing they have a missing import. -Regex { +Regex { // expected-error {{regex builder requires the 'RegexBuilder' module be imported'}} Capture { // expected-error {{cannot find 'Capture' in scope}} /abc/ } diff --git a/test/stmt/statements.swift b/test/stmt/statements.swift index adfd72a651994..f859a8d815973 100644 --- a/test/stmt/statements.swift +++ b/test/stmt/statements.swift @@ -409,7 +409,7 @@ func matching_pattern_recursion(zs: [Int]) { // expected-note {{'zs' declared he } switch 42 { - case { + case { // expected-error {{expression pattern of type '() -> ()' cannot match values of type 'Int'}} for i in ws { // expected-error {{cannot find 'ws' in scope; did you mean 'zs'?}} } }: break