fail_todo_undefined_impl.carbon 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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() -> i32 {
  18. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE+8]]:10: error: accessing member from impl before the end of its definition [ImplAccessMemberBeforeComplete]
  19. // CHECK:STDERR: return C.F();
  20. // CHECK:STDERR: ^~~
  21. // CHECK:STDERR:
  22. // CHECK:STDERR: fail_todo_undefined_impl.carbon:[[@LINE-8]]:3: error: impl declared but not defined [ImplMissingDefinition]
  23. // CHECK:STDERR: extend impl as I;
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. return 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. // CHECK:STDOUT: --- fail_todo_undefined_impl.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %I.type: type = facet_type <@I> [template]
  37. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  38. // CHECK:STDOUT: %F.type.cf0: type = fn_type @F.1 [template]
  39. // CHECK:STDOUT: %F.bc6: %F.type.cf0 = struct_value () [template]
  40. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type %I.type [template]
  41. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%F.decl [template]
  42. // CHECK:STDOUT: %C: type = class_type @C [template]
  43. // CHECK:STDOUT: %impl_witness.85b: <witness> = impl_witness (<error>) [template]
  44. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  45. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  46. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  47. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  48. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.2 [template]
  49. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [template]
  50. // CHECK:STDOUT: %I.facet.b45: %I.type = facet_value %C, %impl_witness.85b [template]
  51. // CHECK:STDOUT: %.575: type = fn_type_with_self_type %F.type.cf0, %I.facet.b45 [template]
  52. // CHECK:STDOUT: %impl_witness.054: <witness> = impl_witness (@impl.2.%F.decl) [template]
  53. // CHECK:STDOUT: %F.type.5d6: type = fn_type @F.3 [template]
  54. // CHECK:STDOUT: %F.a2e: %F.type.5d6 = struct_value () [template]
  55. // CHECK:STDOUT: %I.facet.4ac: %I.type = facet_value %C, %impl_witness.054 [template]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: imports {
  59. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  60. // CHECK:STDOUT: .Int = %Core.Int
  61. // CHECK:STDOUT: import Core//prelude
  62. // CHECK:STDOUT: import Core//prelude/...
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: file {
  67. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  68. // CHECK:STDOUT: .Core = imports.%Core
  69. // CHECK:STDOUT: .I = %I.decl
  70. // CHECK:STDOUT: .C = %C.decl
  71. // CHECK:STDOUT: .F = %F.decl
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %Core.import = import Core
  74. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%I.type] {} {}
  75. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  76. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.2 [template = constants.%F.c41] {
  77. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  78. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  81. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  82. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  83. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: impl_decl @impl.2 [template] {} {
  86. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  87. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (@impl.2.%F.decl) [template = constants.%impl_witness.054]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: interface @I {
  93. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  94. // CHECK:STDOUT: %F.decl: %F.type.cf0 = fn_decl @F.1 [template = constants.%F.bc6] {} {}
  95. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %F.decl [template = constants.%assoc0]
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .Self = %Self
  99. // CHECK:STDOUT: .F = %assoc0
  100. // CHECK:STDOUT: witness = (%F.decl)
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: impl @impl.1: %Self.ref as %I.ref;
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: impl @impl.2: %C.ref as %I.ref {
  106. // CHECK:STDOUT: %F.decl: %F.type.5d6 = fn_decl @F.3 [template = constants.%F.a2e] {} {}
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: !members:
  109. // CHECK:STDOUT: .F = %F.decl
  110. // CHECK:STDOUT: witness = file.%impl_witness
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: class @C {
  114. // CHECK:STDOUT: impl_decl @impl.1 [template] {} {
  115. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  116. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %impl_witness: <witness> = impl_witness (<error>) [template = constants.%impl_witness.85b]
  119. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  120. // CHECK:STDOUT: complete_type_witness = %complete_type
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: !members:
  123. // CHECK:STDOUT: .Self = constants.%C
  124. // CHECK:STDOUT: extend @impl.1.%I.ref
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: generic fn @F.1(@I.%Self: %I.type) {
  128. // CHECK:STDOUT: fn();
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @F.2() -> %i32 {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  134. // CHECK:STDOUT: %F.ref: %I.assoc_type = name_ref F, @I.%assoc0 [template = constants.%assoc0]
  135. // CHECK:STDOUT: %impl.elem0: %.575 = impl_witness_access constants.%impl_witness.85b, element0 [template = <error>]
  136. // CHECK:STDOUT: return <error>
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: fn @F.3() {
  140. // CHECK:STDOUT: !entry:
  141. // CHECK:STDOUT: return
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: specific @F.1(constants.%I.facet.4ac) {}
  147. // CHECK:STDOUT: