fail_else_missing.carbon 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/if_expr/fail_else_missing.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/if_expr/fail_else_missing.carbon
  10. fn F() {
  11. // CHECK:STDERR: fail_else_missing.carbon:[[@LINE+3]]:30: ERROR: Expected `else` after `if ... then ...`.
  12. // CHECK:STDERR: var n: i32 = if true then 1;
  13. // CHECK:STDERR: ^
  14. var n: i32 = if true then 1;
  15. }
  16. // CHECK:STDOUT: - filename: fail_else_missing.carbon
  17. // CHECK:STDOUT: parse_tree: [
  18. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  19. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  20. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'F'},
  21. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  22. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  23. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  24. // CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
  25. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
  26. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  27. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  28. // CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
  29. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  30. // CHECK:STDOUT: {kind: 'IfExprIf', text: 'if', subtree_size: 2},
  31. // CHECK:STDOUT: {kind: 'IntLiteral', text: '1'},
  32. // CHECK:STDOUT: {kind: 'IfExprThen', text: 'then', subtree_size: 2},
  33. // CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes},
  34. // CHECK:STDOUT: {kind: 'IfExprElse', text: 'if', has_error: yes, subtree_size: 6},
  35. // CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 12},
  36. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 18},
  37. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  38. // CHECK:STDOUT: ]