diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 975b57d9125d2..70bea706011e1 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -2142,7 +2142,9 @@ bool TrailingClosureAmbiguityFailure::diagnoseAsNote() { return false; const ParameterList *paramList = callee->getParameters(); - const ParamDecl *param = paramList->getArray().back(); + if (!paramList || paramList->size() == 0) + return false; + const ParamDecl *param = paramList->back(); // Soundness-check that the trailing closure corresponds to this parameter. if (!param->hasInterfaceType() || diff --git a/validation-test/compiler_crashers/TrailingClosureAmbiguityFailure-diagnoseAsNote-d62041.swift b/validation-test/compiler_crashers_fixed/TrailingClosureAmbiguityFailure-diagnoseAsNote-d62041.swift similarity index 82% rename from validation-test/compiler_crashers/TrailingClosureAmbiguityFailure-diagnoseAsNote-d62041.swift rename to validation-test/compiler_crashers_fixed/TrailingClosureAmbiguityFailure-diagnoseAsNote-d62041.swift index bbbc6b3e4d540..6e78cfc8ab1a6 100644 --- a/validation-test/compiler_crashers/TrailingClosureAmbiguityFailure-diagnoseAsNote-d62041.swift +++ b/validation-test/compiler_crashers_fixed/TrailingClosureAmbiguityFailure-diagnoseAsNote-d62041.swift @@ -1,5 +1,5 @@ // {"kind":"typecheck","signature":"swift::constraints::TrailingClosureAmbiguityFailure::diagnoseAsNote()","signatureAssert":"Assertion failed: (!empty()), function back"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s { struct a { init (); diff --git a/validation-test/compiler_crashers_fixed/issue-85364.swift b/validation-test/compiler_crashers_fixed/issue-85364.swift new file mode 100644 index 0000000000000..ce66778201aab --- /dev/null +++ b/validation-test/compiler_crashers_fixed/issue-85364.swift @@ -0,0 +1,27 @@ +// RUN: %target-typecheck-verify-swift -swift-version 6 +// Checks that the compiler correctly diagnoses ambiguous initializers using +// trailing closures, rather than crashing. +// +// Fixes #85364 + +struct S1 { // expected-note {{found this candidate}} \ + // expected-note {{'S1' previously declared here}} + var c: () -> Void +} + +S1 {} // expected-error {{ambiguous use of 'init'}} + +struct S1 { // expected-note {{found this candidate}} \ + // expected-error {{invalid redeclaration of 'S1'}} + func callAsFunction(_: () -> Void) {} +} + +struct S2 { + init() {} // expected-note {{found this candidate}} + + init(_ block: () -> Void) { block() } // expected-note {{found this candidate}} + + func callAsFunction(_ block: () -> Void) { block() } +} + +S2 {} // expected-error {{ambiguous use of 'init'}}