import_access.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/alias/import_access.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/import_access.carbon
  13. // ============================================================================
  14. // Setup files
  15. // ============================================================================
  16. // --- def.carbon
  17. package Test library "[[@TEST_NAME]]";
  18. class C {}
  19. private alias A = C;
  20. // ============================================================================
  21. // Test files
  22. // ============================================================================
  23. // --- def.impl.carbon
  24. impl package Test library "[[@TEST_NAME]]";
  25. var inst: A = {};
  26. // --- fail_local_def.carbon
  27. package Test library "[[@TEST_NAME]]";
  28. import library "def";
  29. // CHECK:STDERR: fail_local_def.carbon:[[@LINE+4]]:11: error: name `A` not found [NameNotFound]
  30. // CHECK:STDERR: var inst: A = {};
  31. // CHECK:STDERR: ^
  32. // CHECK:STDERR:
  33. var inst: A = {};
  34. // --- fail_other_def.carbon
  35. package Other library "[[@TEST_NAME]]";
  36. import Test library "def";
  37. // CHECK:STDERR: fail_other_def.carbon:[[@LINE+4]]:11: error: member name `A` not found in `Test` [MemberNameNotFoundInInstScope]
  38. // CHECK:STDERR: var inst: Test.A = {};
  39. // CHECK:STDERR: ^~~~~~
  40. // CHECK:STDERR:
  41. var inst: Test.A = {};
  42. // CHECK:STDOUT: --- def.carbon
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: constants {
  45. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  46. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  47. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  52. // CHECK:STDOUT: .C = %C.decl
  53. // CHECK:STDOUT: .A [private] = %A
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  56. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [concrete = constants.%C]
  57. // CHECK:STDOUT: %A: type = alias_binding A, %C.decl [concrete = constants.%C]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @C {
  61. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  62. // CHECK:STDOUT: complete_type_witness = %complete_type
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: !members:
  65. // CHECK:STDOUT: .Self = constants.%C
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: --- def.impl.carbon
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: constants {
  71. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  72. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  73. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  74. // CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
  75. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  76. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: imports {
  80. // CHECK:STDOUT: %Test.C = import_ref Test//def, C, unloaded
  81. // CHECK:STDOUT: %Test.A: type = import_ref Test//def, A, loaded [concrete = constants.%C]
  82. // CHECK:STDOUT: %Test.import_ref.8f2: <witness> = import_ref Test//def, loc4_10, loaded [concrete = constants.%complete_type]
  83. // CHECK:STDOUT: %Test.import_ref.2c4 = import_ref Test//def, inst{{[0-9A-F]+}} [no loc], unloaded
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: file {
  87. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  88. // CHECK:STDOUT: .C = imports.%Test.C
  89. // CHECK:STDOUT: .A [private] = imports.%Test.A
  90. // CHECK:STDOUT: .inst = %inst
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %Test.import = import Test
  93. // CHECK:STDOUT: %default.import = import <none>
  94. // CHECK:STDOUT: name_binding_decl {
  95. // CHECK:STDOUT: %inst.patt: %pattern_type = ref_binding_pattern inst [concrete]
  96. // CHECK:STDOUT: %inst.var_patt: %pattern_type = var_pattern %inst.patt [concrete]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %inst.var: ref %C = var %inst.var_patt [concrete]
  99. // CHECK:STDOUT: %A.ref: type = name_ref A, imports.%Test.A [concrete = constants.%C]
  100. // CHECK:STDOUT: %inst: ref %C = ref_binding inst, %inst.var [concrete = %inst.var]
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: class @C [from "def.carbon"] {
  104. // CHECK:STDOUT: complete_type_witness = imports.%Test.import_ref.8f2
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !members:
  107. // CHECK:STDOUT: .Self = imports.%Test.import_ref.2c4
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: fn @__global_init() {
  111. // CHECK:STDOUT: !entry:
  112. // CHECK:STDOUT: %.loc4_16.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  113. // CHECK:STDOUT: %.loc4_16.2: init %C = class_init (), file.%inst.var [concrete = constants.%C.val]
  114. // CHECK:STDOUT: %.loc4_1: init %C = converted %.loc4_16.1, %.loc4_16.2 [concrete = constants.%C.val]
  115. // CHECK:STDOUT: assign file.%inst.var, %.loc4_1
  116. // CHECK:STDOUT: return
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: --- fail_local_def.carbon
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: constants {
  122. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  123. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: imports {
  127. // CHECK:STDOUT: %Test.C = import_ref Test//def, C, unloaded
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: file {
  131. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  132. // CHECK:STDOUT: .C = imports.%Test.C
  133. // CHECK:STDOUT: .A = <poisoned>
  134. // CHECK:STDOUT: .inst = %inst
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %default.import = import <none>
  137. // CHECK:STDOUT: name_binding_decl {
  138. // CHECK:STDOUT: %inst.patt: <error> = ref_binding_pattern inst [concrete]
  139. // CHECK:STDOUT: %inst.var_patt: <error> = var_pattern %inst.patt [concrete]
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %inst.var: ref <error> = var %inst.var_patt [concrete = <error>]
  142. // CHECK:STDOUT: %A.ref: <error> = name_ref A, <error> [concrete = <error>]
  143. // CHECK:STDOUT: %inst: ref <error> = ref_binding inst, <error> [concrete = <error>]
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn @__global_init() {
  147. // CHECK:STDOUT: !entry:
  148. // CHECK:STDOUT: %.loc10: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  149. // CHECK:STDOUT: assign file.%inst.var, <error>
  150. // CHECK:STDOUT: return
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: --- fail_other_def.carbon
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: constants {
  156. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  157. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: imports {
  161. // CHECK:STDOUT: %Test: <namespace> = namespace file.%Test.import, [concrete] {
  162. // CHECK:STDOUT: .A = <poisoned>
  163. // CHECK:STDOUT: import Test//def
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: file {
  168. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  169. // CHECK:STDOUT: .Test = imports.%Test
  170. // CHECK:STDOUT: .inst = %inst
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT: %Test.import = import Test
  173. // CHECK:STDOUT: name_binding_decl {
  174. // CHECK:STDOUT: %inst.patt: <error> = ref_binding_pattern inst [concrete]
  175. // CHECK:STDOUT: %inst.var_patt: <error> = var_pattern %inst.patt [concrete]
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: %inst.var: ref <error> = var %inst.var_patt [concrete = <error>]
  178. // CHECK:STDOUT: %.1: <error> = splice_block <error> [concrete = <error>] {
  179. // CHECK:STDOUT: %Test.ref: <namespace> = name_ref Test, imports.%Test [concrete = imports.%Test]
  180. // CHECK:STDOUT: %A.ref: <error> = name_ref A, <error> [concrete = <error>]
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: %inst: ref <error> = ref_binding inst, <error> [concrete = <error>]
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: fn @__global_init() {
  186. // CHECK:STDOUT: !entry:
  187. // CHECK:STDOUT: %.loc10: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  188. // CHECK:STDOUT: assign file.%inst.var, <error>
  189. // CHECK:STDOUT: return
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT: