fail_variety.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_variety.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/operators/fail_variety.carbon
  10. fn F() {
  11. // CHECK:STDERR: fail_variety.carbon:[[@LINE+20]]:21: error: operator `=` can only be used as a complete statement [StatementOperatorAsSubExpr]
  12. // CHECK:STDERR: n = a * b + c * d = d * d << e & f - not g;
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR:
  15. // CHECK:STDERR: fail_variety.carbon:[[@LINE+16]]:29: error: parentheses are required to disambiguate operator precedence [OperatorRequiresParentheses]
  16. // CHECK:STDERR: n = a * b + c * d = d * d << e & f - not g;
  17. // CHECK:STDERR: ^~
  18. // CHECK:STDERR:
  19. // CHECK:STDERR: fail_variety.carbon:[[@LINE+12]]:34: error: parentheses are required to disambiguate operator precedence [OperatorRequiresParentheses]
  20. // CHECK:STDERR: n = a * b + c * d = d * d << e & f - not g;
  21. // CHECK:STDERR: ^
  22. // CHECK:STDERR:
  23. // CHECK:STDERR: fail_variety.carbon:[[@LINE+8]]:38: error: parentheses are required to disambiguate operator precedence [OperatorRequiresParentheses]
  24. // CHECK:STDERR: n = a * b + c * d = d * d << e & f - not g;
  25. // CHECK:STDERR: ^
  26. // CHECK:STDERR:
  27. // CHECK:STDERR: fail_variety.carbon:[[@LINE+4]]:40: error: parentheses are required around this unary `not` operator [UnaryOperatorRequiresParentheses]
  28. // CHECK:STDERR: n = a * b + c * d = d * d << e & f - not g;
  29. // CHECK:STDERR: ^~~
  30. // CHECK:STDERR:
  31. n = a * b + c * d = d * d << e & f - not g;
  32. }
  33. // CHECK:STDOUT: - filename: fail_variety.carbon
  34. // CHECK:STDOUT: parse_tree: [
  35. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  36. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  37. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  38. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  39. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
  40. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  41. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  42. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'a'},
  43. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'b'},
  44. // CHECK:STDOUT: {kind: 'InfixOperatorStar', text: '*', subtree_size: 3},
  45. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'c'},
  46. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'd'},
  47. // CHECK:STDOUT: {kind: 'InfixOperatorStar', text: '*', subtree_size: 3},
  48. // CHECK:STDOUT: {kind: 'InfixOperatorPlus', text: '+', subtree_size: 7},
  49. // CHECK:STDOUT: {kind: 'InfixOperatorEqual', text: '=', subtree_size: 9},
  50. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'd'},
  51. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'd'},
  52. // CHECK:STDOUT: {kind: 'InfixOperatorStar', text: '*', subtree_size: 3},
  53. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'e'},
  54. // CHECK:STDOUT: {kind: 'InfixOperatorLessLess', text: '<<', has_error: yes, subtree_size: 5},
  55. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'f'},
  56. // CHECK:STDOUT: {kind: 'InfixOperatorAmp', text: '&', has_error: yes, subtree_size: 7},
  57. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'g'},
  58. // CHECK:STDOUT: {kind: 'PrefixOperatorNot', text: 'not', subtree_size: 2},
  59. // CHECK:STDOUT: {kind: 'InfixOperatorMinus', text: '-', has_error: yes, subtree_size: 10},
  60. // CHECK:STDOUT: {kind: 'InfixOperatorEqual', text: '=', has_error: yes, subtree_size: 20},
  61. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 21},
  62. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 27},
  63. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  64. // CHECK:STDOUT: ]