mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 07:15:00 +01:00
Fixes the malformed parse tree produced for an invalid let struct
pattern containing a single identifier (e.g., `let {s};`).
As pointed out by @DavidLoftus, the parser should produce a parse tree
similar to that of `let {ref s};`, since both are missing a binding
power operator `:`, and both do not have a `.` preceding the identifier
(i.e., `state.in_field_shorthand_pattern == true`).
This means that the parser can produce an the `InvalidParse` node just
as it does for `let {ref s};`.
Closes #7674
29 lines
1.4 KiB
Plaintext
29 lines
1.4 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
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/let/fail_let_struct_identifier_only.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/let/fail_let_struct_identifier_only.carbon
|
|
|
|
// CHECK:STDERR: fail_let_struct_identifier_only.carbon:[[@LINE+4]]:7: error: expected `:` or `:?` in binding pattern [ExpectedBindingPattern]
|
|
// CHECK:STDERR: let {s};
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
let {s};
|
|
|
|
// CHECK:STDOUT: - filename: fail_let_struct_identifier_only.carbon
|
|
// CHECK:STDOUT: ╭─FileStart ''
|
|
// CHECK:STDOUT: │ ╭─LetIntroducer 'let'
|
|
// CHECK:STDOUT: │ │ ╭─StructPatternStart '{'
|
|
// CHECK:STDOUT: │ │ │ ╭─IdentifierNameNotBeforeSignature 's'
|
|
// CHECK:STDOUT: │ │ │ ├─InvalidParse '}' has_error
|
|
// CHECK:STDOUT: │ │ │ ├─InvalidParse '}' has_error
|
|
// CHECK:STDOUT: │ │ ├─LetBindingPattern 's' has_error
|
|
// CHECK:STDOUT: │ ├─StructPattern '}' has_error
|
|
// CHECK:STDOUT: ├─LetDecl ';'
|
|
// CHECK:STDOUT: ├─FileEnd ''
|
|
// CHECK:STDOUT: (root)
|