fail_in_nested_scope.carbon 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_in_nested_scope.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_in_nested_scope.carbon
  10. class A {
  11. // CHECK:STDERR: fail_in_nested_scope.carbon:[[@LINE+7]]:3: 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_in_nested_scope.carbon:[[@LINE-4]]:1: note: first declaration is here [FirstDecl]
  15. // CHECK:STDERR: class A {
  16. // CHECK:STDERR: ^~~~~
  17. // CHECK:STDERR:
  18. import B;
  19. }
  20. fn F() {
  21. // CHECK:STDERR: fail_in_nested_scope.carbon:[[@LINE+7]]:3: error: `import` declarations must come after the `package` declaration (if present) and before any other entities in the file [ImportTooLate]
  22. // CHECK:STDERR: import C;
  23. // CHECK:STDERR: ^~~~~~
  24. // CHECK:STDERR: fail_in_nested_scope.carbon:[[@LINE-15]]:1: note: first declaration is here [FirstDecl]
  25. // CHECK:STDERR: class A {
  26. // CHECK:STDERR: ^~~~~
  27. // CHECK:STDERR:
  28. import C;
  29. }
  30. // CHECK:STDOUT: - filename: fail_in_nested_scope.carbon
  31. // CHECK:STDOUT: parse_tree: [
  32. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  33. // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
  34. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'A'},
  35. // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 3},
  36. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  37. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  38. // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 6},
  39. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  40. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  41. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  42. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  43. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  44. // CHECK:STDOUT: {kind: 'ImportIntroducer', text: 'import'},
  45. // CHECK:STDOUT: {kind: 'ImportDecl', text: ';', has_error: yes, subtree_size: 2},
  46. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 8},
  47. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  48. // CHECK:STDOUT: ]