From 000b4f3fa5ef4d9913b64d07cbf1a59c338329bc Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Fri, 20 Mar 2026 11:25:00 -0700 Subject: [PATCH] Handle errors in form binding without crashing. (#6936) Closes #6920 --- toolchain/check/pattern_match.cpp | 1 + toolchain/check/testdata/let/form.carbon | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 toolchain/check/testdata/let/form.carbon diff --git a/toolchain/check/pattern_match.cpp b/toolchain/check/pattern_match.cpp index bce996edf1b9..15c1246deea2 100644 --- a/toolchain/check/pattern_match.cpp +++ b/toolchain/check/pattern_match.cpp @@ -320,6 +320,7 @@ static auto ConversionKindFor(Context& context, SemIR::Inst pattern, context.TODO(entry.pattern_id, "Support symbolic form bindings"); [[fallthrough]]; case SemIR::ValueForm::Kind: + case SemIR::ErrorInst::Kind: return ConversionTarget::Value; default: CARBON_FATAL("Unexpected form {0}", form_inst); diff --git a/toolchain/check/testdata/let/form.carbon b/toolchain/check/testdata/let/form.carbon new file mode 100644 index 000000000000..8e90e6b55e16 --- /dev/null +++ b/toolchain/check/testdata/let/form.carbon @@ -0,0 +1,23 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon +// +// AUTOUPDATE +// TIP: To test this file alone, run: +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/let/form.carbon +// TIP: To dump output, run: +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/form.carbon + +// --- fail_todo_form_binding.carbon +library "[[@TEST_NAME]]"; + +// CHECK:STDERR: fail_todo_form_binding.carbon:[[@LINE+7]]:9: error: cannot implicitly convert expression of type `()` to `Core.Form` [ConversionFailure] +// CHECK:STDERR: let x:? () = (); +// CHECK:STDERR: ^~ +// CHECK:STDERR: fail_todo_form_binding.carbon:[[@LINE+4]]:9: note: type `()` does not implement interface `Core.ImplicitAs(Core.Form)` [MissingImplInMemberAccessInContext] +// CHECK:STDERR: let x:? () = (); +// CHECK:STDERR: ^~ +// CHECK:STDERR: +let x:? () = ();