fail_todo_undefined_impl.carbon 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/impl/lookup/fail_todo_undefined_impl.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/lookup/fail_todo_undefined_impl.carbon
  14. interface I {
  15. fn F();
  16. }
  17. class C {
  18. // This doesn't match `impl C as I` below under proposal #3763.
  19. extend impl as I;
  20. }
  21. fn F() {
  22. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE+4]]:3: error: accessing member from impl before it has a defined value [ImplAccessMemberBeforeSet]
  23. // CHECK:STDERR: C.F();
  24. // CHECK:STDERR: ^~~
  25. // CHECK:STDERR:
  26. C.F();
  27. }
  28. // TODO: This should be written `impl C.(Self as I)` or `impl C.(as I)`, once
  29. // that is supported.
  30. impl C as I {
  31. fn F() {}
  32. }
  33. fn G() {
  34. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE+8]]:3: error: accessing member from impl before it has a defined value [ImplAccessMemberBeforeSet]
  35. // CHECK:STDERR: C.F();
  36. // CHECK:STDERR: ^~~
  37. // CHECK:STDERR:
  38. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE-22]]:3: error: impl declared but not defined [ImplMissingDefinition]
  39. // CHECK:STDERR: extend impl as I;
  40. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  41. // CHECK:STDERR:
  42. C.F();
  43. }
  44. // CHECK:STDOUT: --- fail_todo_undefined_impl.carbon
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: constants {
  47. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  48. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
  49. // CHECK:STDOUT: %I.WithSelf.F.type.08c: type = fn_type @I.WithSelf.F, @I.WithSelf(%Self) [symbolic]
  50. // CHECK:STDOUT: %I.WithSelf.F.705: %I.WithSelf.F.type.08c = struct_value () [symbolic]
  51. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  52. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.WithSelf.%I.WithSelf.F.decl [concrete]
  53. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  54. // CHECK:STDOUT: %I.impl_witness.ad4: <witness> = impl_witness @C.as.I.impl.b72.%I.impl_witness_table [concrete]
  55. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  56. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  57. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  58. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  59. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  60. // CHECK:STDOUT: %C.type.facet: %type = facet_value %C, () [concrete]
  61. // CHECK:STDOUT: %I.WithSelf.F.type.b59: type = fn_type @I.WithSelf.F, @I.WithSelf(%C.type.facet) [concrete]
  62. // CHECK:STDOUT: %I.WithSelf.F.521: %I.WithSelf.F.type.b59 = struct_value () [concrete]
  63. // CHECK:STDOUT: %I.facet.990: %I.type = facet_value %C, (%I.impl_witness.ad4) [concrete]
  64. // CHECK:STDOUT: %I.WithSelf.F.type.25c: type = fn_type @I.WithSelf.F, @I.WithSelf(%I.facet.990) [concrete]
  65. // CHECK:STDOUT: %I.WithSelf.F.570: %I.WithSelf.F.type.25c = struct_value () [concrete]
  66. // CHECK:STDOUT: %.840: type = fn_type_with_self_type %I.WithSelf.F.type.25c, %I.facet.990 [concrete]
  67. // CHECK:STDOUT: %I.impl_witness.df9: <witness> = impl_witness @C.as.I.impl.e47.%I.impl_witness_table [concrete]
  68. // CHECK:STDOUT: %C.as.I.impl.F.type: type = fn_type @C.as.I.impl.F [concrete]
  69. // CHECK:STDOUT: %C.as.I.impl.F: %C.as.I.impl.F.type = struct_value () [concrete]
  70. // CHECK:STDOUT: %I.facet.54e: %I.type = facet_value %C, (%I.impl_witness.df9) [concrete]
  71. // CHECK:STDOUT: %I.WithSelf.F.type.31f: type = fn_type @I.WithSelf.F, @I.WithSelf(%I.facet.54e) [concrete]
  72. // CHECK:STDOUT: %I.WithSelf.F.564: %I.WithSelf.F.type.31f = struct_value () [concrete]
  73. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  74. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {
  78. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  79. // CHECK:STDOUT: .I = %I.decl
  80. // CHECK:STDOUT: .C = %C.decl
  81. // CHECK:STDOUT: .F = %F.decl
  82. // CHECK:STDOUT: .G = %G.decl
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  85. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  86. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  87. // CHECK:STDOUT: impl_decl @C.as.I.impl.e47 [concrete] {} {
  88. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  89. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: interface @I {
  95. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  96. // CHECK:STDOUT: %I.WithSelf.decl = interface_with_self_decl @I [concrete]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !with Self:
  99. // CHECK:STDOUT: %I.WithSelf.F.decl: @I.WithSelf.%I.WithSelf.F.type (%I.WithSelf.F.type.08c) = fn_decl @I.WithSelf.F [symbolic = @I.WithSelf.%I.WithSelf.F (constants.%I.WithSelf.F.705)] {} {}
  100. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.WithSelf.F.decl [concrete = constants.%assoc0]
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: !members:
  103. // CHECK:STDOUT: .Self = %Self
  104. // CHECK:STDOUT: .F = @I.WithSelf.%assoc0
  105. // CHECK:STDOUT: witness = (@I.WithSelf.%I.WithSelf.F.decl)
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !requires:
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: impl @C.as.I.impl.b72: %Self.ref as %I.ref;
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: impl @C.as.I.impl.e47: %C.ref as %I.ref {
  113. // CHECK:STDOUT: %C.as.I.impl.F.decl: %C.as.I.impl.F.type = fn_decl @C.as.I.impl.F [concrete = constants.%C.as.I.impl.F] {} {}
  114. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (%C.as.I.impl.F.decl), @C.as.I.impl.e47 [concrete]
  115. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness.df9]
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !members:
  118. // CHECK:STDOUT: .F = %C.as.I.impl.F.decl
  119. // CHECK:STDOUT: witness = %I.impl_witness
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: class @C {
  123. // CHECK:STDOUT: impl_decl @C.as.I.impl.b72 [concrete] {} {
  124. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  125. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  128. // CHECK:STDOUT: complete_type_witness = %complete_type
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: !members:
  131. // CHECK:STDOUT: .Self = constants.%C
  132. // CHECK:STDOUT: .I = <poisoned>
  133. // CHECK:STDOUT: .F = <poisoned>
  134. // CHECK:STDOUT: extend @C.as.I.impl.b72.%I.ref
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: generic fn @I.WithSelf.F(@I.%Self: %I.type) {
  138. // CHECK:STDOUT: fn();
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @F() {
  142. // CHECK:STDOUT: !entry:
  143. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  144. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.WithSelf.%assoc0 [concrete = constants.%assoc0]
  145. // CHECK:STDOUT: %impl.elem0: %.840 = impl_witness_access constants.%I.impl_witness.ad4, element0 [concrete = <error>]
  146. // CHECK:STDOUT: return
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: fn @C.as.I.impl.F() {
  150. // CHECK:STDOUT: !entry:
  151. // CHECK:STDOUT: return
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: fn @G() {
  155. // CHECK:STDOUT: !entry:
  156. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  157. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.WithSelf.%assoc0 [concrete = constants.%assoc0]
  158. // CHECK:STDOUT: %impl.elem0: %.840 = impl_witness_access constants.%I.impl_witness.ad4, element0 [concrete = <error>]
  159. // CHECK:STDOUT: return
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: specific @I.WithSelf(constants.%Self) {
  163. // CHECK:STDOUT: !definition:
  164. // CHECK:STDOUT: %Self => constants.%Self
  165. // CHECK:STDOUT: %I.WithSelf.F.type => constants.%I.WithSelf.F.type.08c
  166. // CHECK:STDOUT: %I.WithSelf.F => constants.%I.WithSelf.F.705
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: specific @I.WithSelf.F(constants.%Self) {}
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: specific @I.WithSelf(constants.%C.type.facet) {
  172. // CHECK:STDOUT: !definition:
  173. // CHECK:STDOUT: %Self => constants.%C.type.facet
  174. // CHECK:STDOUT: %I.WithSelf.F.type => constants.%I.WithSelf.F.type.b59
  175. // CHECK:STDOUT: %I.WithSelf.F => constants.%I.WithSelf.F.521
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: specific @I.WithSelf(constants.%I.facet.990) {
  179. // CHECK:STDOUT: !definition:
  180. // CHECK:STDOUT: %Self => constants.%I.facet.990
  181. // CHECK:STDOUT: %I.WithSelf.F.type => constants.%I.WithSelf.F.type.25c
  182. // CHECK:STDOUT: %I.WithSelf.F => constants.%I.WithSelf.F.570
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: specific @I.WithSelf(constants.%I.facet.54e) {
  186. // CHECK:STDOUT: !definition:
  187. // CHECK:STDOUT: %Self => constants.%I.facet.54e
  188. // CHECK:STDOUT: %I.WithSelf.F.type => constants.%I.WithSelf.F.type.31f
  189. // CHECK:STDOUT: %I.WithSelf.F => constants.%I.WithSelf.F.564
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: specific @I.WithSelf.F(constants.%I.facet.54e) {}
  193. // CHECK:STDOUT: