fail_top_level_if.carbon 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_top_level_if.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_top_level_if.carbon
  10. fn F() {
  11. // CHECK:STDERR: fail_top_level_if.carbon:[[@LINE+12]]:6: error: expected `(` after `if` [ExpectedParenAfter]
  12. // CHECK:STDERR: if true then 1 else 2;
  13. // CHECK:STDERR: ^~~~
  14. // CHECK:STDERR:
  15. // CHECK:STDERR: fail_top_level_if.carbon:[[@LINE+8]]:11: error: expected braced code block [ExpectedCodeBlock]
  16. // CHECK:STDERR: if true then 1 else 2;
  17. // CHECK:STDERR: ^~~~
  18. // CHECK:STDERR:
  19. // CHECK:STDERR: fail_top_level_if.carbon:[[@LINE+4]]:11: error: expected expression [ExpectedExpr]
  20. // CHECK:STDERR: if true then 1 else 2;
  21. // CHECK:STDERR: ^~~~
  22. // CHECK:STDERR:
  23. if true then 1 else 2;
  24. }
  25. // CHECK:STDOUT: - filename: fail_top_level_if.carbon
  26. // CHECK:STDOUT: parse_tree: [
  27. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  28. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  29. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  30. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  31. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
  32. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  33. // CHECK:STDOUT: {kind: 'IfConditionStart', text: 'if', has_error: yes},
  34. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  35. // CHECK:STDOUT: {kind: 'IfCondition', text: 'if', has_error: yes, subtree_size: 3},
  36. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: 'then', has_error: yes},
  37. // CHECK:STDOUT: {kind: 'InvalidParse', text: 'then', has_error: yes},
  38. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', has_error: yes, subtree_size: 2},
  39. // CHECK:STDOUT: {kind: 'CodeBlock', text: 'then', has_error: yes, subtree_size: 4},
  40. // CHECK:STDOUT: {kind: 'IfStatement', text: 'if', subtree_size: 8},
  41. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 14},
  42. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  43. // CHECK:STDOUT: ]