fail_todo_undefined_impl.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.F.type: type = fn_type @I.F [concrete]
  50. // CHECK:STDOUT: %I.F: %I.F.type = struct_value () [concrete]
  51. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  52. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%I.F.decl [concrete]
  53. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  54. // CHECK:STDOUT: %I.impl_witness.874: <witness> = impl_witness @C.%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: %I.facet.2cf: %I.type = facet_value %C, (%I.impl_witness.874) [concrete]
  60. // CHECK:STDOUT: %.4d6: type = fn_type_with_self_type %I.F.type, %I.facet.2cf [concrete]
  61. // CHECK:STDOUT: %I.impl_witness.686: <witness> = impl_witness file.%I.impl_witness_table [concrete]
  62. // CHECK:STDOUT: %C.as.I.impl.F.type: type = fn_type @C.as.I.impl.F [concrete]
  63. // CHECK:STDOUT: %C.as.I.impl.F: %C.as.I.impl.F.type = struct_value () [concrete]
  64. // CHECK:STDOUT: %I.facet.137: %I.type = facet_value %C, (%I.impl_witness.686) [concrete]
  65. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  66. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: file {
  70. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  71. // CHECK:STDOUT: .I = %I.decl
  72. // CHECK:STDOUT: .C = %C.decl
  73. // CHECK:STDOUT: .F = %F.decl
  74. // CHECK:STDOUT: .G = %G.decl
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  77. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  78. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  79. // CHECK:STDOUT: impl_decl @C.as.I.impl.7de [concrete] {} {
  80. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  81. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (@C.as.I.impl.7de.%C.as.I.impl.F.decl), @C.as.I.impl.7de [concrete]
  84. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness.686]
  85. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: interface @I {
  89. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  90. // CHECK:STDOUT: %I.F.decl: %I.F.type = fn_decl @I.F [concrete = constants.%I.F] {} {}
  91. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.F.decl [concrete = constants.%assoc0]
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .Self = %Self
  95. // CHECK:STDOUT: .F = %assoc0
  96. // CHECK:STDOUT: witness = (%I.F.decl)
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !requires:
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: impl @C.as.I.impl.bd0: %Self.ref as %I.ref;
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: impl @C.as.I.impl.7de: %C.ref as %I.ref {
  104. // 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] {} {}
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !members:
  107. // CHECK:STDOUT: .F = %C.as.I.impl.F.decl
  108. // CHECK:STDOUT: witness = file.%I.impl_witness
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: class @C {
  112. // CHECK:STDOUT: impl_decl @C.as.I.impl.bd0 [concrete] {} {
  113. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  114. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %I.impl_witness_table = impl_witness_table (), @C.as.I.impl.bd0 [concrete]
  117. // CHECK:STDOUT: %I.impl_witness: <witness> = impl_witness %I.impl_witness_table [concrete = constants.%I.impl_witness.874]
  118. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  119. // CHECK:STDOUT: complete_type_witness = %complete_type
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Self = constants.%C
  123. // CHECK:STDOUT: .I = <poisoned>
  124. // CHECK:STDOUT: .F = <poisoned>
  125. // CHECK:STDOUT: extend @C.as.I.impl.bd0.%I.ref
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: generic fn @I.F(@I.%Self: %I.type) {
  129. // CHECK:STDOUT: fn();
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: fn @F() {
  133. // CHECK:STDOUT: !entry:
  134. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  135. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.%assoc0 [concrete = constants.%assoc0]
  136. // CHECK:STDOUT: %impl.elem0: %.4d6 = impl_witness_access constants.%I.impl_witness.874, element0 [concrete = <error>]
  137. // CHECK:STDOUT: return
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: fn @C.as.I.impl.F() {
  141. // CHECK:STDOUT: !entry:
  142. // CHECK:STDOUT: return
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn @G() {
  146. // CHECK:STDOUT: !entry:
  147. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  148. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.%assoc0 [concrete = constants.%assoc0]
  149. // CHECK:STDOUT: %impl.elem0: %.4d6 = impl_witness_access constants.%I.impl_witness.874, element0 [concrete = <error>]
  150. // CHECK:STDOUT: return
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: specific @I.F(constants.%Self) {}
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: specific @I.F(constants.%I.facet.137) {}
  156. // CHECK:STDOUT: