fail_trailing_comments.carbon 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // Trailing comments should produce errors, but we should continue to parse (and
  6. // diagnose) code errors beyond them.
  7. var a: i32 = 1; // trailing comment
  8. var b: 32 = 13; // more trailing comment
  9. var c: i32 = 0.4; // still more trailing comment
  10. // We keep the auto-update marker below the above so check lines don't disrupt
  11. // the trailing comment lines with similar prefixes.
  12. // AUTOUPDATE
  13. // CHECK:STDERR: fail_trailing_comments.carbon:[[@LINE-7]]:19: ERROR: Trailing comments are not permitted.
  14. // CHECK:STDERR: var a: i32 = 1; // trailing comment
  15. // CHECK:STDERR: ^
  16. // CHECK:STDERR: fail_trailing_comments.carbon:[[@LINE-9]]:19: ERROR: Trailing comments are not permitted.
  17. // CHECK:STDERR: var b: 32 = 13; // more trailing comment
  18. // CHECK:STDERR: ^
  19. // CHECK:STDERR: fail_trailing_comments.carbon:[[@LINE-11]]:19: ERROR: Trailing comments are not permitted.
  20. // CHECK:STDERR: var c: i32 = 0.4; // still more trailing comment
  21. // CHECK:STDERR: ^
  22. // CHECK:STDOUT: - filename: fail_trailing_comments.carbon
  23. // CHECK:STDOUT: tokens: [
  24. // CHECK:STDOUT: { index: 0, kind: 'StartOfFile', line: {{ *\d+}}, column: 1, indent: 1, spelling: '', has_trailing_space: true },
  25. // CHECK:STDOUT: { index: 1, kind: 'Var', line: {{ *}}[[@LINE-19]], column: 1, indent: 1, spelling: 'var', has_trailing_space: true },
  26. // CHECK:STDOUT: { index: 2, kind: 'Identifier', line: {{ *}}[[@LINE-20]], column: 5, indent: 1, spelling: 'a', identifier: 0 },
  27. // CHECK:STDOUT: { index: 3, kind: 'Colon', line: {{ *}}[[@LINE-21]], column: 6, indent: 1, spelling: ':', has_trailing_space: true },
  28. // CHECK:STDOUT: { index: 4, kind: 'IntegerTypeLiteral', line: {{ *}}[[@LINE-22]], column: 8, indent: 1, spelling: 'i32', has_trailing_space: true },
  29. // CHECK:STDOUT: { index: 5, kind: 'Equal', line: {{ *}}[[@LINE-23]], column: 12, indent: 1, spelling: '=', has_trailing_space: true },
  30. // CHECK:STDOUT: { index: 6, kind: 'IntegerLiteral', line: {{ *}}[[@LINE-24]], column: 14, indent: 1, spelling: '1', value: `1` },
  31. // CHECK:STDOUT: { index: 7, kind: 'Semi', line: {{ *}}[[@LINE-25]], column: 15, indent: 1, spelling: ';', has_trailing_space: true },
  32. // CHECK:STDOUT: { index: 8, kind: 'Var', line: {{ *}}[[@LINE-25]], column: 1, indent: 1, spelling: 'var', has_trailing_space: true },
  33. // CHECK:STDOUT: { index: 9, kind: 'Identifier', line: {{ *}}[[@LINE-26]], column: 5, indent: 1, spelling: 'b', identifier: 1 },
  34. // CHECK:STDOUT: { index: 10, kind: 'Colon', line: {{ *}}[[@LINE-27]], column: 6, indent: 1, spelling: ':', has_trailing_space: true },
  35. // CHECK:STDOUT: { index: 11, kind: 'IntegerLiteral', line: {{ *}}[[@LINE-28]], column: 8, indent: 1, spelling: '32', value: `32`, has_trailing_space: true },
  36. // CHECK:STDOUT: { index: 12, kind: 'Equal', line: {{ *}}[[@LINE-29]], column: 11, indent: 1, spelling: '=', has_trailing_space: true },
  37. // CHECK:STDOUT: { index: 13, kind: 'IntegerLiteral', line: {{ *}}[[@LINE-30]], column: 13, indent: 1, spelling: '13', value: `13` },
  38. // CHECK:STDOUT: { index: 14, kind: 'Semi', line: {{ *}}[[@LINE-31]], column: 15, indent: 1, spelling: ';', has_trailing_space: true },
  39. // CHECK:STDOUT: { index: 15, kind: 'Var', line: {{ *}}[[@LINE-31]], column: 1, indent: 1, spelling: 'var', has_trailing_space: true },
  40. // CHECK:STDOUT: { index: 16, kind: 'Identifier', line: {{ *}}[[@LINE-32]], column: 5, indent: 1, spelling: 'c', identifier: 2 },
  41. // CHECK:STDOUT: { index: 17, kind: 'Colon', line: {{ *}}[[@LINE-33]], column: 6, indent: 1, spelling: ':', has_trailing_space: true },
  42. // CHECK:STDOUT: { index: 18, kind: 'IntegerTypeLiteral', line: {{ *}}[[@LINE-34]], column: 8, indent: 1, spelling: 'i32', has_trailing_space: true },
  43. // CHECK:STDOUT: { index: 19, kind: 'Equal', line: {{ *}}[[@LINE-35]], column: 12, indent: 1, spelling: '=', has_trailing_space: true },
  44. // CHECK:STDOUT: { index: 20, kind: 'RealLiteral', line: {{ *}}[[@LINE-36]], column: 14, indent: 1, spelling: '0.4', value: `4*10^-1` },
  45. // CHECK:STDOUT: { index: 21, kind: 'Semi', line: {{ *}}[[@LINE-37]], column: 17, indent: 1, spelling: ';', has_trailing_space: true },
  46. // CHECK:STDOUT: { index: 22, kind: 'EndOfFile', line: {{ *}}[[@LINE+1]], column: {{ *\d+}}, indent: 1, spelling: '' },
  47. // CHECK:STDOUT: ]