fail_precedence_as.carbon 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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+3]]:12: Parentheses are required to disambiguate operator precedence.
  9. // CHECK:STDERR: not true as bool;
  10. // CHECK:STDERR: ^
  11. not true as bool;
  12. // No ordering between most binary operators and `as`.
  13. // CHECK:STDERR: fail_precedence_as.carbon:[[@LINE+3]]:9: Parentheses are required to disambiguate operator precedence.
  14. // CHECK:STDERR: 1 + 1 as i32;
  15. // CHECK:STDERR: ^
  16. 1 + 1 as i32;
  17. // CHECK:STDERR: fail_precedence_as.carbon:[[@LINE+3]]:9: Parentheses are required to disambiguate operator precedence.
  18. // CHECK:STDERR: 5 % 2 as i32;
  19. // CHECK:STDERR: ^
  20. 5 % 2 as i32;
  21. }
  22. // CHECK:STDOUT: [
  23. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  24. // CHECK:STDOUT: {kind: 'Name', text: 'F'},
  25. // CHECK:STDOUT: {kind: 'ParameterListStart', text: '('},
  26. // CHECK:STDOUT: {kind: 'Name', text: 'n'},
  27. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  28. // CHECK:STDOUT: {kind: 'PatternBinding', text: ':', subtree_size: 3},
  29. // CHECK:STDOUT: {kind: 'ParameterList', text: ')', subtree_size: 5},
  30. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 8},
  31. // CHECK:STDOUT: {kind: 'Literal', text: 'true'},
  32. // CHECK:STDOUT: {kind: 'PrefixOperator', text: 'not', subtree_size: 2},
  33. // CHECK:STDOUT: {kind: 'Literal', text: 'bool'},
  34. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', has_error: yes, subtree_size: 4},
  35. // CHECK:STDOUT: {kind: 'ExpressionStatement', text: ';', subtree_size: 5},
  36. // CHECK:STDOUT: {kind: 'Literal', text: '1'},
  37. // CHECK:STDOUT: {kind: 'Literal', text: '1'},
  38. // CHECK:STDOUT: {kind: 'InfixOperator', text: '+', subtree_size: 3},
  39. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  40. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', has_error: yes, subtree_size: 5},
  41. // CHECK:STDOUT: {kind: 'ExpressionStatement', text: ';', subtree_size: 6},
  42. // CHECK:STDOUT: {kind: 'Literal', text: '5'},
  43. // CHECK:STDOUT: {kind: 'Literal', text: '2'},
  44. // CHECK:STDOUT: {kind: 'InfixOperator', text: '%', subtree_size: 3},
  45. // CHECK:STDOUT: {kind: 'Literal', text: 'i32'},
  46. // CHECK:STDOUT: {kind: 'InfixOperator', text: 'as', has_error: yes, subtree_size: 5},
  47. // CHECK:STDOUT: {kind: 'ExpressionStatement', text: ';', subtree_size: 6},
  48. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 26},
  49. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  50. // CHECK:STDOUT: ]