fail_after_decl_repeated.carbon 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/packages/import/fail_after_decl_repeated.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/packages/import/fail_after_decl_repeated.carbon
  10. fn A();
  11. // CHECK:STDERR: fail_after_decl_repeated.carbon:[[@LINE+7]]:1: error: `import` declarations must come after the `package` declaration (if present) and before any other entities in the file [ImportTooLate]
  12. // CHECK:STDERR: import B;
  13. // CHECK:STDERR: ^~~~~~
  14. // CHECK:STDERR: fail_after_decl_repeated.carbon:[[@LINE-5]]:1: note: first declaration is here [FirstDecl]
  15. // CHECK:STDERR: fn A();
  16. // CHECK:STDERR: ^~
  17. // CHECK:STDERR:
  18. import B;
  19. // Note this is still invalid, but doesn't warn because it's sequential.
  20. import C;
  21. // CHECK:STDERR: fail_after_decl_repeated.carbon:[[@LINE+7]]:1: error: the `package` declaration must be the first non-comment line [PackageTooLate]
  22. // CHECK:STDERR: package D;
  23. // CHECK:STDERR: ^~~~~~~
  24. // CHECK:STDERR: fail_after_decl_repeated.carbon:[[@LINE-16]]:1: note: first non-comment line is here [FirstNonCommentLine]
  25. // CHECK:STDERR: fn A();
  26. // CHECK:STDERR: ^~
  27. // CHECK:STDERR:
  28. package D;
  29. fn E();
  30. // CHECK:STDERR: fail_after_decl_repeated.carbon:[[@LINE+7]]:1: error: `import` declarations must come after the `package` declaration (if present) and before any other entities in the file [ImportTooLate]
  31. // CHECK:STDERR: import F;
  32. // CHECK:STDERR: ^~~~~~
  33. // CHECK:STDERR: fail_after_decl_repeated.carbon:[[@LINE-27]]:1: note: first declaration is here [FirstDecl]
  34. // CHECK:STDERR: fn A();
  35. // CHECK:STDERR: ^~
  36. // CHECK:STDERR:
  37. import F;
  38. // Note this is still invalid, but doesn't warn because it's sequential.
  39. import G;
  40. // CHECK:STDOUT: - filename: fail_after_decl_repeated.carbon
  41. // CHECK:STDOUT: parse_tree: [
  42. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  43. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  44. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'A'},
  45. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  46. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  47. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  48. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  49. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  50. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  51. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  52. // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'},
  53. // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', has_error: yes, subtree_size: 2},
  54. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  55. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'E'},
  56. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  57. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  58. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  59. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  60. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  61. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  62. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  63. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  64. // CHECK:STDOUT: ]