fail_export_name_member.carbon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/packages/fail_export_name_member.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/packages/fail_export_name_member.carbon
  14. // --- a.carbon
  15. package Foo library "[[@TEST_NAME]]";
  16. class C {
  17. var n: {};
  18. }
  19. // --- fail_b.carbon
  20. package Foo library "[[@TEST_NAME]]";
  21. import library "a";
  22. // TODO: This diagnostic doesn't clearly explain the problem. We should instead
  23. // say something like: Only namespace-scope names can be exported.
  24. // CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:8: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
  25. // CHECK:STDERR: export C.n;
  26. // CHECK:STDERR: ^
  27. // CHECK:STDERR: fail_b.carbon:[[@LINE-7]]:1: in import [InImport]
  28. // CHECK:STDERR: a.carbon:4:1: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
  29. // CHECK:STDERR: class C {
  30. // CHECK:STDERR: ^~~~~~~~~
  31. // CHECK:STDERR:
  32. export C.n;
  33. // CHECK:STDOUT: --- a.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  37. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  38. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  39. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %empty_struct_type [concrete]
  40. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %empty_struct_type} [concrete]
  41. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  46. // CHECK:STDOUT: .C = %C.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: class @C {
  52. // CHECK:STDOUT: %.loc5_11.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  53. // CHECK:STDOUT: %.loc5_11.2: type = converted %.loc5_11.1, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  54. // CHECK:STDOUT: %.loc5_8: %C.elem = field_decl n, element0 [concrete]
  55. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.n [concrete = constants.%complete_type]
  56. // CHECK:STDOUT: complete_type_witness = %complete_type
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: !members:
  59. // CHECK:STDOUT: .Self = constants.%C
  60. // CHECK:STDOUT: .n = %.loc5_8
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: --- fail_b.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  67. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  68. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %empty_struct_type} [concrete]
  69. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: imports {
  73. // CHECK:STDOUT: %Foo.C: type = import_ref Foo//a, C, loaded [concrete = constants.%C]
  74. // CHECK:STDOUT: %Foo.import_ref.9fc: <witness> = import_ref Foo//a, loc6_1, loaded [concrete = constants.%complete_type]
  75. // CHECK:STDOUT: %Foo.import_ref.1d1 = import_ref Foo//a, inst{{[0-9A-F]+}} [no loc], unloaded
  76. // CHECK:STDOUT: %Foo.import_ref.8c5 = import_ref Foo//a, loc5_8, unloaded
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: file {
  80. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  81. // CHECK:STDOUT: .C = imports.%Foo.C
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %default.import = import <none>
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: class @C [from "a.carbon"] {
  87. // CHECK:STDOUT: complete_type_witness = imports.%Foo.import_ref.9fc
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: !members:
  90. // CHECK:STDOUT: .Self = imports.%Foo.import_ref.1d1
  91. // CHECK:STDOUT: .n = imports.%Foo.import_ref.8c5
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: