fail_todo_generic_default_fn.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/interface/fail_todo_generic_default_fn.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_todo_generic_default_fn.carbon
  14. interface I(T:! type) {
  15. // TODO: Use `default` here.
  16. fn F[self: Self]() -> Self;
  17. }
  18. // CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE+7]]:16: error: duplicate name `F` being declared in the same scope [NameDeclDuplicate]
  19. // CHECK:STDERR: fn I(T:! type).F[self: Self]() -> Self { return self; }
  20. // CHECK:STDERR: ^
  21. // CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE-6]]:3: note: name is previously declared here [NameDeclPrevious]
  22. // CHECK:STDERR: fn F[self: Self]() -> Self;
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. // CHECK:STDERR:
  25. fn I(T:! type).F[self: Self]() -> Self { return self; }
  26. // CHECK:STDOUT: --- fail_todo_generic_default_fn.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  30. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  31. // CHECK:STDOUT: %I.type.dac: type = generic_interface_type @I [concrete]
  32. // CHECK:STDOUT: %I.generic: %I.type.dac = struct_value () [concrete]
  33. // CHECK:STDOUT: %I.type.325: type = facet_type <@I, @I(%T)> [symbolic]
  34. // CHECK:STDOUT: %Self: %I.type.325 = bind_symbolic_name Self, 1 [symbolic]
  35. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
  36. // CHECK:STDOUT: %pattern_type.4be: type = pattern_type %Self.as_type [symbolic]
  37. // CHECK:STDOUT: %F.type.2aef59.1: type = fn_type @F.loc17, @I(%T) [symbolic]
  38. // CHECK:STDOUT: %F.bb2dd4.1: %F.type.2aef59.1 = struct_value () [symbolic]
  39. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I, @I(%T) [symbolic]
  40. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%F.decl [symbolic]
  41. // CHECK:STDOUT: %F.type.2aef59.2: type = fn_type @F.loc27, @I(%T) [symbolic]
  42. // CHECK:STDOUT: %F.bb2dd4.2: %F.type.2aef59.2 = struct_value () [symbolic]
  43. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %Self.as_type [symbolic]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  48. // CHECK:STDOUT: .I = %I.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %I.decl: %I.type.dac = interface_decl @I [concrete = constants.%I.generic] {
  51. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  52. // CHECK:STDOUT: } {
  53. // CHECK:STDOUT: %T.loc15_13.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc15_13.2 (constants.%T)]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %F.decl: %F.type.2aef59.2 = fn_decl @F.loc27 [symbolic = constants.%F.bb2dd4.2] {
  56. // CHECK:STDOUT: %self.patt: @F.loc27.%pattern_type (%pattern_type.4be) = binding_pattern self [concrete]
  57. // CHECK:STDOUT: %self.param_patt: @F.loc27.%pattern_type (%pattern_type.4be) = value_param_pattern %self.patt, call_param0 [concrete]
  58. // CHECK:STDOUT: %return.patt: @F.loc27.%pattern_type (%pattern_type.4be) = return_slot_pattern [concrete]
  59. // CHECK:STDOUT: %return.param_patt: @F.loc27.%pattern_type (%pattern_type.4be) = out_param_pattern %return.patt, call_param1 [concrete]
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %T.loc27_6: type = bind_symbolic_name T, 0 [symbolic = @I.%T.loc15_13.2 (constants.%T)]
  62. // CHECK:STDOUT: %.loc27_35.1: @F.loc27.%I.type (%I.type.325) = specific_constant @I.%Self.1, @I(constants.%T) [symbolic = %Self (constants.%Self)]
  63. // CHECK:STDOUT: %Self.ref.loc27_35: @F.loc27.%I.type (%I.type.325) = name_ref Self, %.loc27_35.1 [symbolic = %Self (constants.%Self)]
  64. // CHECK:STDOUT: %Self.as_type.loc27_35: type = facet_access_type %Self.ref.loc27_35 [symbolic = %Self.as_type.loc27_24.2 (constants.%Self.as_type)]
  65. // CHECK:STDOUT: %.loc27_35.2: type = converted %Self.ref.loc27_35, %Self.as_type.loc27_35 [symbolic = %Self.as_type.loc27_24.2 (constants.%Self.as_type)]
  66. // CHECK:STDOUT: %self.param: @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type) = value_param call_param0
  67. // CHECK:STDOUT: %.loc27_24.1: type = splice_block %.loc27_24.3 [symbolic = %Self.as_type.loc27_24.2 (constants.%Self.as_type)] {
  68. // CHECK:STDOUT: %.loc27_24.2: @F.loc27.%I.type (%I.type.325) = specific_constant @I.%Self.1, @I(constants.%T) [symbolic = %Self (constants.%Self)]
  69. // CHECK:STDOUT: %Self.ref.loc27_24: @F.loc27.%I.type (%I.type.325) = name_ref Self, %.loc27_24.2 [symbolic = %Self (constants.%Self)]
  70. // CHECK:STDOUT: %Self.as_type.loc27_24.1: type = facet_access_type %Self.ref.loc27_24 [symbolic = %Self.as_type.loc27_24.2 (constants.%Self.as_type)]
  71. // CHECK:STDOUT: %.loc27_24.3: type = converted %Self.ref.loc27_24, %Self.as_type.loc27_24.1 [symbolic = %Self.as_type.loc27_24.2 (constants.%Self.as_type)]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %self: @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type) = bind_name self, %self.param
  74. // CHECK:STDOUT: %return.param: ref @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type) = out_param call_param1
  75. // CHECK:STDOUT: %return: ref @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type) = return_slot %return.param
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: generic interface @I(%T.loc15_13.1: type) {
  80. // CHECK:STDOUT: %T.loc15_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc15_13.2 (constants.%T)]
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: !definition:
  83. // CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T.loc15_13.2)> [symbolic = %I.type (constants.%I.type.325)]
  84. // CHECK:STDOUT: %Self.2: @I.%I.type (%I.type.325) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  85. // CHECK:STDOUT: %F.type: type = fn_type @F.loc17, @I(%T.loc15_13.2) [symbolic = %F.type (constants.%F.type.2aef59.1)]
  86. // CHECK:STDOUT: %F: @I.%F.type (%F.type.2aef59.1) = struct_value () [symbolic = %F (constants.%F.bb2dd4.1)]
  87. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I, @I(%T.loc15_13.2) [symbolic = %I.assoc_type (constants.%I.assoc_type)]
  88. // CHECK:STDOUT: %assoc0.loc17_29.2: @I.%I.assoc_type (%I.assoc_type) = assoc_entity element0, %F.decl [symbolic = %assoc0.loc17_29.2 (constants.%assoc0)]
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: interface {
  91. // CHECK:STDOUT: %Self.1: @I.%I.type (%I.type.325) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  92. // CHECK:STDOUT: %F.decl: @I.%F.type (%F.type.2aef59.1) = fn_decl @F.loc17 [symbolic = @I.%F (constants.%F.bb2dd4.1)] {
  93. // CHECK:STDOUT: %self.patt: @F.loc17.%pattern_type (%pattern_type.4be) = binding_pattern self [concrete]
  94. // CHECK:STDOUT: %self.param_patt: @F.loc17.%pattern_type (%pattern_type.4be) = value_param_pattern %self.patt, call_param0 [concrete]
  95. // CHECK:STDOUT: %return.patt: @F.loc17.%pattern_type (%pattern_type.4be) = return_slot_pattern [concrete]
  96. // CHECK:STDOUT: %return.param_patt: @F.loc17.%pattern_type (%pattern_type.4be) = out_param_pattern %return.patt, call_param1 [concrete]
  97. // CHECK:STDOUT: } {
  98. // CHECK:STDOUT: %.loc17_25.1: @F.loc17.%I.type (%I.type.325) = specific_constant @I.%Self.1, @I(constants.%T) [symbolic = %Self (constants.%Self)]
  99. // CHECK:STDOUT: %Self.ref.loc17_25: @F.loc17.%I.type (%I.type.325) = name_ref Self, %.loc17_25.1 [symbolic = %Self (constants.%Self)]
  100. // CHECK:STDOUT: %Self.as_type.loc17_25: type = facet_access_type %Self.ref.loc17_25 [symbolic = %Self.as_type.loc17_14.1 (constants.%Self.as_type)]
  101. // CHECK:STDOUT: %.loc17_25.2: type = converted %Self.ref.loc17_25, %Self.as_type.loc17_25 [symbolic = %Self.as_type.loc17_14.1 (constants.%Self.as_type)]
  102. // CHECK:STDOUT: %self.param: @F.loc17.%Self.as_type.loc17_14.1 (%Self.as_type) = value_param call_param0
  103. // CHECK:STDOUT: %.loc17_14.1: type = splice_block %.loc17_14.3 [symbolic = %Self.as_type.loc17_14.1 (constants.%Self.as_type)] {
  104. // CHECK:STDOUT: %.loc17_14.2: @F.loc17.%I.type (%I.type.325) = specific_constant @I.%Self.1, @I(constants.%T) [symbolic = %Self (constants.%Self)]
  105. // CHECK:STDOUT: %Self.ref.loc17_14: @F.loc17.%I.type (%I.type.325) = name_ref Self, %.loc17_14.2 [symbolic = %Self (constants.%Self)]
  106. // CHECK:STDOUT: %Self.as_type.loc17_14.2: type = facet_access_type %Self.ref.loc17_14 [symbolic = %Self.as_type.loc17_14.1 (constants.%Self.as_type)]
  107. // CHECK:STDOUT: %.loc17_14.3: type = converted %Self.ref.loc17_14, %Self.as_type.loc17_14.2 [symbolic = %Self.as_type.loc17_14.1 (constants.%Self.as_type)]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %self: @F.loc17.%Self.as_type.loc17_14.1 (%Self.as_type) = bind_name self, %self.param
  110. // CHECK:STDOUT: %return.param: ref @F.loc17.%Self.as_type.loc17_14.1 (%Self.as_type) = out_param call_param1
  111. // CHECK:STDOUT: %return: ref @F.loc17.%Self.as_type.loc17_14.1 (%Self.as_type) = return_slot %return.param
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %assoc0.loc17_29.1: @I.%I.assoc_type (%I.assoc_type) = assoc_entity element0, %F.decl [symbolic = %assoc0.loc17_29.2 (constants.%assoc0)]
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: !members:
  116. // CHECK:STDOUT: .Self = %Self.1
  117. // CHECK:STDOUT: .F = %assoc0.loc17_29.1
  118. // CHECK:STDOUT: witness = (%F.decl)
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: generic fn @F.loc17(@I.%T.loc15_13.1: type, @I.%Self.1: @I.%I.type (%I.type.325)) {
  123. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  124. // CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T)> [symbolic = %I.type (constants.%I.type.325)]
  125. // CHECK:STDOUT: %Self: @F.loc17.%I.type (%I.type.325) = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self)]
  126. // CHECK:STDOUT: %Self.as_type.loc17_14.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc17_14.1 (constants.%Self.as_type)]
  127. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc17_14.1 [symbolic = %pattern_type (constants.%pattern_type.4be)]
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn(%self.param: @F.loc17.%Self.as_type.loc17_14.1 (%Self.as_type)) -> @F.loc17.%Self.as_type.loc17_14.1 (%Self.as_type);
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: generic fn @F.loc27(%T.loc27_6: type, @I.%Self.1: @I.%I.type (%I.type.325)) {
  133. // CHECK:STDOUT: %T.loc27_24: type = bind_symbolic_name T, 0 [symbolic = %T.loc27_24 (constants.%T)]
  134. // CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T.loc27_24)> [symbolic = %I.type (constants.%I.type.325)]
  135. // CHECK:STDOUT: %Self: @F.loc27.%I.type (%I.type.325) = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self)]
  136. // CHECK:STDOUT: %Self.as_type.loc27_24.2: type = facet_access_type %Self [symbolic = %Self.as_type.loc27_24.2 (constants.%Self.as_type)]
  137. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc27_24.2 [symbolic = %pattern_type (constants.%pattern_type.4be)]
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: !definition:
  140. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %Self.as_type.loc27_24.2 [symbolic = %require_complete (constants.%require_complete)]
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: fn(%self.param: @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type)) -> @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type) {
  143. // CHECK:STDOUT: !entry:
  144. // CHECK:STDOUT: %self.ref: @F.loc27.%Self.as_type.loc27_24.2 (%Self.as_type) = name_ref self, %self
  145. // CHECK:STDOUT: return %self.ref
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: specific @I(constants.%T) {
  150. // CHECK:STDOUT: %T.loc15_13.2 => constants.%T
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: !definition:
  153. // CHECK:STDOUT: %I.type => constants.%I.type.325
  154. // CHECK:STDOUT: %Self.2 => constants.%Self
  155. // CHECK:STDOUT: %F.type => constants.%F.type.2aef59.1
  156. // CHECK:STDOUT: %F => constants.%F.bb2dd4.1
  157. // CHECK:STDOUT: %I.assoc_type => constants.%I.assoc_type
  158. // CHECK:STDOUT: %assoc0.loc17_29.2 => constants.%assoc0
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: specific @F.loc17(constants.%T, constants.%Self) {
  162. // CHECK:STDOUT: %T => constants.%T
  163. // CHECK:STDOUT: %I.type => constants.%I.type.325
  164. // CHECK:STDOUT: %Self => constants.%Self
  165. // CHECK:STDOUT: %Self.as_type.loc17_14.1 => constants.%Self.as_type
  166. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.4be
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: specific @F.loc27(constants.%T, constants.%Self) {
  170. // CHECK:STDOUT: %T.loc27_24 => constants.%T
  171. // CHECK:STDOUT: %I.type => constants.%I.type.325
  172. // CHECK:STDOUT: %Self => constants.%Self
  173. // CHECK:STDOUT: %Self.as_type.loc27_24.2 => constants.%Self.as_type
  174. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.4be
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT: