Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ();
Expand Down
27 changes: 27 additions & 0 deletions validation-test/compiler_crashers_fixed/issue-85364.swift
Original file line number Diff line number Diff line change
@@ -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'}}