fail_star_minus.carbon 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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_star_minus.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/operators/fail_star_minus.carbon
  10. // TODO: There are two possible fixes that would make this expression legal:
  11. // `n * -n` and `n* - n`. The parser doesn't realize that the first fix is
  12. // available because it has already accepted that first part of the expression,
  13. // so it is recovering by using the second option, but the diagnostic should
  14. // ideally offer (or consider) both fixes as alternatives.
  15. // CHECK:STDERR: fail_star_minus.carbon:[[@LINE+4]]:16: error: whitespace missing after binary operator [BinaryOperatorRequiresWhitespace]
  16. // CHECK:STDERR: var n: i8 = n* -n;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. var n: i8 = n* -n;
  20. // CHECK:STDOUT: - filename: fail_star_minus.carbon
  21. // CHECK:STDOUT: parse_tree: [
  22. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  23. // CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
  24. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'n'},
  25. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i8'},
  26. // CHECK:STDOUT: {kind: 'VarBindingPattern', text: ':', subtree_size: 3},
  27. // CHECK:STDOUT: {kind: 'VariablePattern', text: 'var', subtree_size: 4},
  28. // CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
  29. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  30. // CHECK:STDOUT: {kind: 'PostfixOperatorStar', text: '*', subtree_size: 2},
  31. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'n'},
  32. // CHECK:STDOUT: {kind: 'InfixOperatorMinus', text: '-', subtree_size: 4},
  33. // CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 11},
  34. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  35. // CHECK:STDOUT: ]