fail_todo_undefined_impl.carbon 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/lookup/fail_todo_undefined_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/lookup/fail_todo_undefined_impl.carbon
  10. interface I {
  11. fn F();
  12. }
  13. class C {
  14. // This doesn't match `impl C as I` below under proposal #3763.
  15. extend impl as I;
  16. }
  17. fn F() {
  18. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE+4]]:3: error: accessing member from impl before it has a defined value [ImplAccessMemberBeforeSet]
  19. // CHECK:STDERR: C.F();
  20. // CHECK:STDERR: ^~~
  21. // CHECK:STDERR:
  22. C.F();
  23. }
  24. // TODO: This should be written `impl C.(Self as I)` or `impl C.(as I)`, once
  25. // that is supported.
  26. impl C as I {
  27. fn F() {}
  28. }
  29. fn G() {
  30. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE+8]]:3: error: accessing member from impl before it has a defined value [ImplAccessMemberBeforeSet]
  31. // CHECK:STDERR: C.F();
  32. // CHECK:STDERR: ^~~
  33. // CHECK:STDERR:
  34. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE-22]]:3: error: impl declared but not defined [ImplMissingDefinition]
  35. // CHECK:STDERR: extend impl as I;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. C.F();
  39. }
  40. // CHECK:STDOUT: --- fail_todo_undefined_impl.carbon
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: constants {
  43. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  44. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  45. // CHECK:STDOUT: %F.type.cf0: type = fn_type @F.1 [concrete]
  46. // CHECK:STDOUT: %F.bc6: %F.type.cf0 = struct_value () [concrete]
  47. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  48. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%F.decl [concrete]
  49. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  50. // CHECK:STDOUT: %I.impl_witness.ab4: <witness> = impl_witness @C.%I.impl_witness_table [concrete]
  51. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  52. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  53. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.2 [concrete]
  54. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [concrete]
  55. // CHECK:STDOUT: %I.facet.580: %I.type = facet_value %C, (%I.impl_witness.ab4) [concrete]
  56. // CHECK:STDOUT: %.3ac: type = fn_type_with_self_type %F.type.cf0, %I.facet.580 [concrete]
  57. // CHECK:STDOUT: %I.impl_witness.6f2: <witness> = impl_witness file.%I.impl_witness_table [concrete]
  58. // CHECK:STDOUT: %F.type.5d6: type = fn_type @F.3 [concrete]
  59. // CHECK:STDOUT: %F.a2e: %F.type.5d6 = struct_value () [concrete]
  60. // CHECK:STDOUT: %I.facet.029: %I.type = facet_value %C, (%I.impl_witness.6f2) [concrete]
  61. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  62. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: imports {
  66. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  67. // CHECK:STDOUT: import Core//prelude
  68. // CHECK:STDOUT: import Core//prelude/...
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: file {
  73. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  74. // CHECK:STDOUT: .Core = imports.%Core
  75. // CHECK:STDOUT: .I = %I.decl
  76. // CHECK:STDOUT: .C = %C.decl
  77. // CHECK:STDOUT: .F = %F.decl
  78. // CHECK:STDOUT: .G = %G.decl
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %Core.import = import Core
  81. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  82. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  83. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.2 [concrete = constants.%F.c41] {} {}
  84. // CHECK:STDOUT: impl_decl @impl.770 [concrete] {} {
  85. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  86. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (@impl.770.%F.decl), @impl.770 [concrete]
  89. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness.6f2]
  90. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: interface @I {
  94. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  95. // CHECK:STDOUT: %F.decl: %F.type.cf0 = fn_decl @F.1 [concrete = constants.%F.bc6] {} {}
  96. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = %Self
  100. // CHECK:STDOUT: .F = %assoc0
  101. // CHECK:STDOUT: witness = (%F.decl)
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: impl @impl.a21: %Self.ref as %I.ref;
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: impl @impl.770: %C.ref as %I.ref {
  107. // CHECK:STDOUT: %F.decl: %F.type.5d6 = fn_decl @F.3 [concrete = constants.%F.a2e] {} {}
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .F = %F.decl
  111. // CHECK:STDOUT: witness = file.%I.impl_witness
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: class @C {
  115. // CHECK:STDOUT: impl_decl @impl.a21 [concrete] {} {
  116. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  117. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (), @impl.a21 [concrete]
  120. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness.ab4]
  121. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  122. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  123. // CHECK:STDOUT: complete_type_witness = %complete_type
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: !members:
  126. // CHECK:STDOUT: .Self = constants.%C
  127. // CHECK:STDOUT: .I = <poisoned>
  128. // CHECK:STDOUT: .F = <poisoned>
  129. // CHECK:STDOUT: extend @impl.a21.%I.ref
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: generic fn @F.1(@I.%Self: %I.type) {
  133. // CHECK:STDOUT: fn();
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: fn @F.2() {
  137. // CHECK:STDOUT: !entry:
  138. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  139. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.%assoc0 [concrete = constants.%assoc0]
  140. // CHECK:STDOUT: %impl.elem0: %.3ac = impl_witness_access constants.%I.impl_witness.ab4, element0 [concrete = <error>]
  141. // CHECK:STDOUT: return
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: fn @F.3() {
  145. // CHECK:STDOUT: !entry:
  146. // CHECK:STDOUT: return
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: fn @G() {
  150. // CHECK:STDOUT: !entry:
  151. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  152. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.%assoc0 [concrete = constants.%assoc0]
  153. // CHECK:STDOUT: %impl.elem0: %.3ac = impl_witness_access constants.%I.impl_witness.ab4, element0 [concrete = <error>]
  154. // CHECK:STDOUT: return
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: specific @F.1(constants.%I.facet.029) {}
  160. // CHECK:STDOUT: