fail_missing_case_arrow.carbon 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/match/fail_missing_case_arrow.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/match/fail_missing_case_arrow.carbon
  10. fn f() -> i32 {
  11. match (3) {
  12. // CHECK:STDERR: fail_missing_case_arrow.carbon:[[@LINE+4]]:17: error: expected `=>` introducing statement block [ExpectedMatchCaseArrow]
  13. // CHECK:STDERR: case x: i32 { return 2; }
  14. // CHECK:STDERR: ^
  15. // CHECK:STDERR:
  16. case x: i32 { return 2; }
  17. // CHECK:STDERR: fail_missing_case_arrow.carbon:[[@LINE+4]]:29: error: expected `=>` introducing statement block [ExpectedMatchCaseArrow]
  18. // CHECK:STDERR: case x: i32 if (x == 3) { return 3; }
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR:
  21. case x: i32 if (x == 3) { return 3; }
  22. }
  23. return 0;
  24. }
  25. // CHECK:STDOUT: - filename: fail_missing_case_arrow.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: 'IntTypeLiteral', text: 'i32'},
  33. // CHECK:STDOUT: {kind: 'ReturnType', text: '->', subtree_size: 2},
  34. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 7},
  35. // CHECK:STDOUT: {kind: 'MatchIntroducer', text: 'match'},
  36. // CHECK:STDOUT: {kind: 'MatchConditionStart', text: '('},
  37. // CHECK:STDOUT: {kind: 'IntLiteral', text: '3'},
  38. // CHECK:STDOUT: {kind: 'MatchCondition', text: ')', subtree_size: 3},
  39. // CHECK:STDOUT: {kind: 'MatchStatementStart', text: '{', subtree_size: 5},
  40. // CHECK:STDOUT: {kind: 'MatchCaseIntroducer', text: 'case'},
  41. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'x'},
  42. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  43. // CHECK:STDOUT: {kind: 'LetBindingPattern', text: ':', subtree_size: 3},
  44. // CHECK:STDOUT: {kind: 'MatchCaseEqualGreater', text: '{', has_error: yes},
  45. // CHECK:STDOUT: {kind: 'MatchCaseStart', text: '{', has_error: yes, subtree_size: 6},
  46. // CHECK:STDOUT: {kind: 'MatchCase', text: '{', has_error: yes, subtree_size: 7},
  47. // CHECK:STDOUT: {kind: 'MatchCaseIntroducer', text: 'case'},
  48. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'x'},
  49. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  50. // CHECK:STDOUT: {kind: 'LetBindingPattern', text: ':', subtree_size: 3},
  51. // CHECK:STDOUT: {kind: 'MatchCaseGuardIntroducer', text: 'if'},
  52. // CHECK:STDOUT: {kind: 'MatchCaseGuardStart', text: '('},
  53. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  54. // CHECK:STDOUT: {kind: 'IntLiteral', text: '3'},
  55. // CHECK:STDOUT: {kind: 'InfixOperatorEqualEqual', text: '==', subtree_size: 3},
  56. // CHECK:STDOUT: {kind: 'MatchCaseGuard', text: ')', subtree_size: 6},
  57. // CHECK:STDOUT: {kind: 'MatchCaseEqualGreater', text: '{', has_error: yes},
  58. // CHECK:STDOUT: {kind: 'MatchCaseStart', text: '{', has_error: yes, subtree_size: 12},
  59. // CHECK:STDOUT: {kind: 'MatchCase', text: '{', has_error: yes, subtree_size: 13},
  60. // CHECK:STDOUT: {kind: 'MatchStatement', text: '}', subtree_size: 26},
  61. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  62. // CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
  63. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  64. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 37},
  65. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  66. // CHECK:STDOUT: ]