import_extend_impl.carbon 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/check/testdata/impl/no_prelude/import_extend_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/import_extend_impl.carbon
  10. // --- extend_impl_library.carbon
  11. library "[[@TEST_NAME]]";
  12. interface I {
  13. fn F();
  14. }
  15. class C {
  16. extend impl as I {
  17. fn F() {}
  18. }
  19. }
  20. // --- fail_todo_use_imported_class_extend_impl.carbon
  21. library "[[@TEST_NAME]]";
  22. import library "extend_impl_library";
  23. fn G(c: C) {
  24. // CHECK:STDERR: fail_todo_use_imported_class_extend_impl.carbon:[[@LINE+4]]:3: error: name `F` not found [NameNotFound]
  25. // CHECK:STDERR: C.F();
  26. // CHECK:STDERR: ^~~
  27. // CHECK:STDERR:
  28. C.F();
  29. // CHECK:STDERR: fail_todo_use_imported_class_extend_impl.carbon:[[@LINE+3]]:3: error: name `F` not found [NameNotFound]
  30. // CHECK:STDERR: c.F();
  31. // CHECK:STDERR: ^~~
  32. c.F();
  33. }
  34. // CHECK:STDOUT: --- extend_impl_library.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %I.type: type = facet_type <@I> [template]
  38. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  39. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  40. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  41. // CHECK:STDOUT: %.1: type = assoc_entity_type %I.type, %F.type.1 [template]
  42. // CHECK:STDOUT: %.2: %.1 = assoc_entity element0, @I.%F.decl [template]
  43. // CHECK:STDOUT: %C: type = class_type @C [template]
  44. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  45. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  46. // CHECK:STDOUT: %.3: <witness> = interface_witness (%F.2) [template]
  47. // CHECK:STDOUT: %.4: type = struct_type {} [template]
  48. // CHECK:STDOUT: %.5: <witness> = complete_type_witness %.4 [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .I = %I.decl
  54. // CHECK:STDOUT: .C = %C.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%I.type] {} {}
  57. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: interface @I {
  61. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  62. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  63. // CHECK:STDOUT: %.loc5: %.1 = assoc_entity element0, %F.decl [template = constants.%.2]
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = %Self
  67. // CHECK:STDOUT: .F = %.loc5
  68. // CHECK:STDOUT: witness = (%F.decl)
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: impl @impl: %Self.ref as %I.ref {
  72. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  73. // CHECK:STDOUT: %.loc9: <witness> = interface_witness (%F.decl) [template = constants.%.3]
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .F = %F.decl
  77. // CHECK:STDOUT: witness = %.loc9
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: class @C {
  81. // CHECK:STDOUT: impl_decl @impl [template] {} {
  82. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  83. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %.loc12: <witness> = complete_type_witness %.4 [template = constants.%.5]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = constants.%C
  89. // CHECK:STDOUT: extend @impl.%I.ref
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: generic fn @F.1(@I.%Self: %I.type) {
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn();
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @F.2() {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: return
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: specific @F.1(constants.%C) {}
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: --- fail_todo_use_imported_class_extend_impl.carbon
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: constants {
  109. // CHECK:STDOUT: %C: type = class_type @C [template]
  110. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  111. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: imports {
  115. // CHECK:STDOUT: %import_ref.1 = import_ref Main//extend_impl_library, inst+1, unloaded
  116. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//extend_impl_library, inst+12, loaded [template = constants.%C]
  117. // CHECK:STDOUT: %import_ref.3 = import_ref Main//extend_impl_library, inst+13, unloaded
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: file {
  121. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  122. // CHECK:STDOUT: .I = imports.%import_ref.1
  123. // CHECK:STDOUT: .C = imports.%import_ref.2
  124. // CHECK:STDOUT: .G = %G.decl
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %default.import = import <invalid>
  127. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  128. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  129. // CHECK:STDOUT: %c.param_patt: %C = value_param_pattern %c.patt, runtime_param0
  130. // CHECK:STDOUT: } {
  131. // CHECK:STDOUT: %C.ref.loc6: type = name_ref C, imports.%import_ref.2 [template = constants.%C]
  132. // CHECK:STDOUT: %c.param: %C = value_param runtime_param0
  133. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: class @C {
  138. // CHECK:STDOUT: !members:
  139. // CHECK:STDOUT: .Self = imports.%import_ref.3
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: fn @G(%c.param_patt: %C) {
  143. // CHECK:STDOUT: !entry:
  144. // CHECK:STDOUT: %C.ref.loc11: type = name_ref C, imports.%import_ref.2 [template = constants.%C]
  145. // CHECK:STDOUT: %F.ref.loc11: <error> = name_ref F, <error> [template = <error>]
  146. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  147. // CHECK:STDOUT: %F.ref.loc15: <error> = name_ref F, <error> [template = <error>]
  148. // CHECK:STDOUT: return
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: