fail_postincrement.carbon 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/operators/fail_postincrement.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/operators/fail_postincrement.carbon
  10. fn F() {
  11. var n: i32 = 0;
  12. // TODO: It'd be nice to produce a custom diagnostic here.
  13. // CHECK:STDERR: fail_postincrement.carbon:[[@LINE+4]]:4: error: expected `;` after expression statement [ExpectedExprSemi]
  14. // CHECK:STDERR: n++;
  15. // CHECK:STDERR: ^~
  16. // CHECK:STDERR:
  17. n++;
  18. // CHECK:STDERR: fail_postincrement.carbon:[[@LINE+4]]:4: error: expected `;` after expression statement [ExpectedExprSemi]
  19. // CHECK:STDERR: n--;
  20. // CHECK:STDERR: ^~
  21. // CHECK:STDERR:
  22. n--;
  23. }
  24. // CHECK:STDOUT: - filename: fail_postincrement.carbon
  25. // CHECK:STDOUT: parse_tree: [
  26. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  27. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  28. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  29. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  30. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
  31. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  32. // CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
  33. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'n'},
  34. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  35. // CHECK:STDOUT: {kind: 'VarBindingPattern', text: ':', subtree_size: 3},
  36. // CHECK:STDOUT: {kind: 'VariablePattern', text: 'var', subtree_size: 4},
  37. // CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
  38. // CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
  39. // CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 8},
  40. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  41. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', has_error: yes, subtree_size: 2},
  42. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  43. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', has_error: yes, subtree_size: 2},
  44. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 18},
  45. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  46. // CHECK:STDOUT: ]