From 90649d60f091febbadaed3648ffeba1821d30595 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Fri, 23 May 2025 12:33:06 -0700 Subject: [PATCH] Fix crash on 'destroy' with return type and no params (#5527) Fuzzer-found crash --- toolchain/check/handle_function.cpp | 4 +++- .../testdata/class/min_prelude/destroy_decl.carbon | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index 4707d16ae8a0..cefa17968bb6 100644 --- a/toolchain/check/handle_function.cpp +++ b/toolchain/check/handle_function.cpp @@ -64,7 +64,9 @@ auto HandleParseNode(Context& context, Parse::ReturnTypeId node_id) -> bool { // not on the pattern stacks yet. They are only needed in that case if we have // a return type, which we now know that we do. if (context.node_stack().PeekNodeKind() == - Parse::NodeKind::IdentifierNameNotBeforeParams) { + Parse::NodeKind::IdentifierNameNotBeforeParams || + context.node_stack().PeekNodeKind() == + Parse::NodeKind::KeywordNameNotBeforeParams) { context.pattern_block_stack().Push(); context.full_pattern_stack().PushFullPattern( FullPatternStack::Kind::ExplicitParamList); diff --git a/toolchain/check/testdata/class/min_prelude/destroy_decl.carbon b/toolchain/check/testdata/class/min_prelude/destroy_decl.carbon index 7d2d59ed59f4..bd0901a3d8ab 100644 --- a/toolchain/check/testdata/class/min_prelude/destroy_decl.carbon +++ b/toolchain/check/testdata/class/min_prelude/destroy_decl.carbon @@ -180,3 +180,16 @@ class C { // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~ // CHECK:STDERR: fn C.destroy.Foo() {} + +// --- fail_return_type_after_no_params.carbon + +library "[[@TEST_NAME]]"; + +// Return type handling special-cases the "no params" case. +class C { + // CHECK:STDERR: fail_return_type_after_no_params.carbon:[[@LINE+4]]:3: error: missing implicit `self` parameter [DestroyFunctionMissingSelf] + // CHECK:STDERR: fn destroy -> (); + // CHECK:STDERR: ^~~~~~~~~~~~~~~~~ + // CHECK:STDERR: + fn destroy -> (); +}