Files
carbon-lang/toolchain/driver/testdata/fail_errors_streamed.carbon
T
Richard Smith 3bbc03f527 Add better algorithm for repairing mismatched brackets (#7574)
Adds an algorithm to compute where to insert brackets to repair
bracketing mismatches during lexing. This takes indentation, as well as
a number of other cues, into account to predict where the brackets
should have gone. Detects when there is ambiguity between solutions and
makes no suggestion in that case. Reduces the problem by splitting on
properly bracketed top-level constructs, then uses a beam search to find
good candidate solutions quickly.

This includes both a fuzzer and an eval tool that can be used to
determine how well the algorithm fares against a given corpus of valid
Carbon code, by damaging it in various ways and seeing whether the
algorithm can correctly fix it. On all the eval modes, this algorithm
can correctly infer the positions for over 80% of lost brackets (and can
correctly restore 95+% of brackets in some modes), with low rates of
incorrect suggestions.

See added documentation for full details.

Assisted-by: Gemini via Antigravity, Claude via Claude Code
2026-08-19 18:55:32 +00:00

28 lines
1.2 KiB
Plaintext

// 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
//
// ARGS: compile --phase=lex --stream-errors %s
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/driver/testdata/fail_errors_streamed.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/driver/testdata/fail_errors_streamed.carbon
fn run(String program) {
return True;
// CHECK:STDERR: fail_errors_streamed.carbon:[[@LINE+11]]:10: error: invalid digit 'a' in decimal numeric literal
// CHECK:STDERR: var x = 3a;
// CHECK:STDERR: ^
// CHECK:STDERR:
// CHECK:STDERR: fail_errors_streamed.carbon:[[@LINE-7]]:24: error: opening symbol without a corresponding closing symbol
// CHECK:STDERR: fn run(String program) {
// CHECK:STDERR: ^
// CHECK:STDERR: fail_errors_streamed.carbon:[[@LINE-8]]:1: note: possibly missing `}` here
// CHECK:STDERR:
// CHECK:STDERR: ^
// CHECK:STDERR:
var x = 3a;