fail_after_decl_repeated.carbon 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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+6]]: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. import F;
  37. // Note this is still invalid, but doesn't warn because it's sequential.
  38. import G;
  39. // CHECK:STDOUT: - filename: fail_after_decl_repeated.carbon
  40. // CHECK:STDOUT: parse_tree: [
  41. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  42. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  43. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'A'},
  44. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  45. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  46. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  47. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  48. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  49. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  50. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  51. // CHECK:STDOUT: {kind: 'PackageIntroducer', text: 'package'},
  52. // CHECK:STDOUT: {kind: 'PackageDecl', text: ';', has_error: yes, subtree_size: 2},
  53. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  54. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'E'},
  55. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  56. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  57. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  58. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  59. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  60. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  61. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  62. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  63. // CHECK:STDOUT: ]