fail_precedence_as.carbon 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. fn F(n: i32) {
  7. // No ordering between `not` and `as`.
  8. // CHECK:STDERR: fail_precedence_as.carbon:[[@LINE+4]]:12: ERROR: Parentheses are required to disambiguate operator precedence.
  9. // CHECK:STDERR: not true as bool;
  10. // CHECK:STDERR: ^~
  11. // CHECK:STDERR:
  12. not true as bool;
  13. // No ordering between most binary operators and `as`.
  14. // CHECK:STDERR: fail_precedence_as.carbon:[[@LINE+4]]:9: ERROR: Parentheses are required to disambiguate operator precedence.
  15. // CHECK:STDERR: 1 + 1 as i32;
  16. // CHECK:STDERR: ^~
  17. // CHECK:STDERR:
  18. 1 + 1 as i32;
  19. // CHECK:STDERR: fail_precedence_as.carbon:[[@LINE+3]]:9: ERROR: Parentheses are required to disambiguate operator precedence.
  20. // CHECK:STDERR: 5 % 2 as i32;
  21. // CHECK:STDERR: ^~
  22. 5 % 2 as i32;
  23. }
  24. // CHECK:STDOUT: - filename: fail_precedence_as.carbon
  25. // CHECK:STDOUT: parse_tree: [
  26. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  27. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  28. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'F'},
  29. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  30. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'n'},
  31. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  32. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  33. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 5},
  34. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 8},
  35. // CHECK:STDOUT: {kind: 'BoolLiteralTrue', text: 'true'},
  36. // CHECK:STDOUT: {kind: 'PrefixOperatorNot', text: 'not', subtree_size: 2},
  37. // CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
  38. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', has_error: yes, subtree_size: 4},
  39. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 5},
  40. // CHECK:STDOUT: {kind: 'IntLiteral', text: '1'},
  41. // CHECK:STDOUT: {kind: 'IntLiteral', text: '1'},
  42. // CHECK:STDOUT: {kind: 'InfixOperatorPlus', text: '+', subtree_size: 3},
  43. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  44. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', has_error: yes, subtree_size: 5},
  45. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 6},
  46. // CHECK:STDOUT: {kind: 'IntLiteral', text: '5'},
  47. // CHECK:STDOUT: {kind: 'IntLiteral', text: '2'},
  48. // CHECK:STDOUT: {kind: 'InfixOperatorPercent', text: '%', subtree_size: 3},
  49. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  50. // CHECK:STDOUT: {kind: 'InfixOperatorAs', text: 'as', has_error: yes, subtree_size: 5},
  51. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 6},
  52. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 26},
  53. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  54. // CHECK:STDOUT: ]