fail_extend_impl_forall.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/fail_extend_impl_forall.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_extend_impl_forall.carbon
  10. interface GenericInterface(T:! type) {
  11. fn F(x: T);
  12. }
  13. class C {
  14. // CHECK:STDERR: fail_extend_impl_forall.carbon:[[@LINE+3]]:3: error: cannot `extend` a parameterized `impl`
  15. // CHECK:STDERR: extend impl forall [T:! type] as GenericInterface(T) {
  16. // CHECK:STDERR: ^~~~~~
  17. extend impl forall [T:! type] as GenericInterface(T) {
  18. fn F(x: T) {}
  19. }
  20. }
  21. // CHECK:STDOUT: --- fail_extend_impl_forall.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  25. // CHECK:STDOUT: %GenericInterface.type.1: type = generic_interface_type @GenericInterface [template]
  26. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  27. // CHECK:STDOUT: %GenericInterface: %GenericInterface.type.1 = struct_value () [template]
  28. // CHECK:STDOUT: %GenericInterface.type.2: type = interface_type @GenericInterface, @GenericInterface(%T) [symbolic]
  29. // CHECK:STDOUT: %Self: %GenericInterface.type.2 = bind_symbolic_name Self, 1 [symbolic]
  30. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1, @GenericInterface(%T) [symbolic]
  31. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [symbolic]
  32. // CHECK:STDOUT: %.2: type = assoc_entity_type %GenericInterface.type.2, %F.type.1 [symbolic]
  33. // CHECK:STDOUT: %.3: %.2 = assoc_entity element0, @GenericInterface.%F.decl [symbolic]
  34. // CHECK:STDOUT: %C: type = class_type @C [template]
  35. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2, @impl(%T) [symbolic]
  36. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [symbolic]
  37. // CHECK:STDOUT: %.4: <witness> = interface_witness (%F.2) [symbolic]
  38. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  39. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: imports {
  43. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  44. // CHECK:STDOUT: import Core//prelude
  45. // CHECK:STDOUT: import Core//prelude/operators
  46. // CHECK:STDOUT: import Core//prelude/types
  47. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  48. // CHECK:STDOUT: import Core//prelude/operators/as
  49. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  50. // CHECK:STDOUT: import Core//prelude/operators/comparison
  51. // CHECK:STDOUT: import Core//prelude/types/bool
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .GenericInterface = %GenericInterface.decl
  59. // CHECK:STDOUT: .C = %C.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.import = import Core
  62. // CHECK:STDOUT: %GenericInterface.decl: %GenericInterface.type.1 = interface_decl @GenericInterface [template = constants.%GenericInterface] {
  63. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  66. // CHECK:STDOUT: %T.loc11_28.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc11_28.2 (constants.%T)]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: generic interface @GenericInterface(%T.loc11_28.1: type) {
  72. // CHECK:STDOUT: %T.loc11_28.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_28.2 (constants.%T)]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !definition:
  75. // CHECK:STDOUT: %GenericInterface.type: type = interface_type @GenericInterface, @GenericInterface(%T.loc11_28.2) [symbolic = %GenericInterface.type (constants.%GenericInterface.type.2)]
  76. // CHECK:STDOUT: %Self.2: %GenericInterface.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  77. // CHECK:STDOUT: %F.type: type = fn_type @F.1, @GenericInterface(%T.loc11_28.2) [symbolic = %F.type (constants.%F.type.1)]
  78. // CHECK:STDOUT: %F: @GenericInterface.%F.type (%F.type.1) = struct_value () [symbolic = %F (constants.%F.1)]
  79. // CHECK:STDOUT: %.loc12_13.2: type = assoc_entity_type @GenericInterface.%GenericInterface.type (%GenericInterface.type.2), @GenericInterface.%F.type (%F.type.1) [symbolic = %.loc12_13.2 (constants.%.2)]
  80. // CHECK:STDOUT: %.loc12_13.3: @GenericInterface.%.loc12_13.2 (%.2) = assoc_entity element0, %F.decl [symbolic = %.loc12_13.3 (constants.%.3)]
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: interface {
  83. // CHECK:STDOUT: %Self.1: @GenericInterface.%GenericInterface.type (%GenericInterface.type.2) = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self)]
  84. // CHECK:STDOUT: %F.decl: @GenericInterface.%F.type (%F.type.1) = fn_decl @F.1 [symbolic = @GenericInterface.%F (constants.%F.1)] {
  85. // CHECK:STDOUT: %x.patt: @F.1.%T (%T) = binding_pattern x
  86. // CHECK:STDOUT: } {
  87. // CHECK:STDOUT: %T.ref: type = name_ref T, @GenericInterface.%T.loc11_28.1 [symbolic = %T (constants.%T)]
  88. // CHECK:STDOUT: %x.param: @F.1.%T (%T) = param x, runtime_param0
  89. // CHECK:STDOUT: %x: @F.1.%T (%T) = bind_name x, %x.param
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %.loc12_13.1: @GenericInterface.%.loc12_13.2 (%.2) = assoc_entity element0, %F.decl [symbolic = %.loc12_13.3 (constants.%.3)]
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .Self = %Self.1
  95. // CHECK:STDOUT: .F = %.loc12_13.1
  96. // CHECK:STDOUT: witness = (%F.decl)
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: generic impl @impl(%T.loc19_23.1: type) {
  101. // CHECK:STDOUT: %T.loc19_23.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc19_23.2 (constants.%T)]
  102. // CHECK:STDOUT: %GenericInterface.type.loc19_52.2: type = interface_type @GenericInterface, @GenericInterface(%T.loc19_23.2) [symbolic = %GenericInterface.type.loc19_52.2 (constants.%GenericInterface.type.2)]
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: !definition:
  105. // CHECK:STDOUT: %F.type: type = fn_type @F.2, @impl(%T.loc19_23.2) [symbolic = %F.type (constants.%F.type.2)]
  106. // CHECK:STDOUT: %F: @impl.%F.type (%F.type.2) = struct_value () [symbolic = %F (constants.%F.2)]
  107. // CHECK:STDOUT: %.loc19_56.2: <witness> = interface_witness (%F) [symbolic = %.loc19_56.2 (constants.%.4)]
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: impl: %Self.ref as %GenericInterface.type.loc19_52.1 {
  110. // CHECK:STDOUT: %F.decl: @impl.%F.type (%F.type.2) = fn_decl @F.2 [symbolic = @impl.%F (constants.%F.2)] {
  111. // CHECK:STDOUT: %x.patt: @F.2.%T (%T) = binding_pattern x
  112. // CHECK:STDOUT: } {
  113. // CHECK:STDOUT: %T.ref: type = name_ref T, @impl.%T.loc19_23.1 [symbolic = %T (constants.%T)]
  114. // CHECK:STDOUT: %x.param: @F.2.%T (%T) = param x, runtime_param0
  115. // CHECK:STDOUT: %x: @F.2.%T (%T) = bind_name x, %x.param
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %.loc19_56.1: <witness> = interface_witness (%F.decl) [symbolic = %.loc19_56.2 (constants.%.4)]
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !members:
  120. // CHECK:STDOUT: .F = %F.decl
  121. // CHECK:STDOUT: witness = %.loc19_56.1
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: class @C {
  126. // CHECK:STDOUT: impl_decl @impl [template] {
  127. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  128. // CHECK:STDOUT: } {
  129. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  130. // CHECK:STDOUT: %T.loc19_23.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc19_23.2 (constants.%T)]
  131. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  132. // CHECK:STDOUT: %GenericInterface.ref: %GenericInterface.type.1 = name_ref GenericInterface, file.%GenericInterface.decl [template = constants.%GenericInterface]
  133. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc19_23.1 [symbolic = %T.loc19_23.2 (constants.%T)]
  134. // CHECK:STDOUT: %GenericInterface.type.loc19_52.1: type = interface_type @GenericInterface, @GenericInterface(constants.%T) [symbolic = %GenericInterface.type.loc19_52.2 (constants.%GenericInterface.type.2)]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %.loc22: <witness> = complete_type_witness %.5 [template = constants.%.6]
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: !members:
  139. // CHECK:STDOUT: .Self = constants.%C
  140. // CHECK:STDOUT: has_error
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: generic fn @F.1(@GenericInterface.%T.loc11_28.1: type, @GenericInterface.%Self.1: @GenericInterface.%GenericInterface.type (%GenericInterface.type.2)) {
  144. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn(%x: @F.1.%T (%T));
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: generic fn @F.2(@impl.%T.loc19_23.1: type) {
  150. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: !definition:
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: fn(%x: @F.2.%T (%T)) {
  155. // CHECK:STDOUT: !entry:
  156. // CHECK:STDOUT: return
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: specific @GenericInterface(constants.%T) {
  161. // CHECK:STDOUT: %T.loc11_28.2 => constants.%T
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: !definition:
  164. // CHECK:STDOUT: %GenericInterface.type => constants.%GenericInterface.type.2
  165. // CHECK:STDOUT: %Self.2 => constants.%Self
  166. // CHECK:STDOUT: %F.type => constants.%F.type.1
  167. // CHECK:STDOUT: %F => constants.%F.1
  168. // CHECK:STDOUT: %.loc12_13.2 => constants.%.2
  169. // CHECK:STDOUT: %.loc12_13.3 => constants.%.3
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: specific @F.1(constants.%T, constants.%Self) {
  173. // CHECK:STDOUT: %T => constants.%T
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: specific @GenericInterface(@GenericInterface.%T.loc11_28.2) {
  177. // CHECK:STDOUT: %T.loc11_28.2 => constants.%T
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: specific @GenericInterface(@impl.%T.loc19_23.2) {
  181. // CHECK:STDOUT: %T.loc11_28.2 => constants.%T
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: specific @impl(constants.%T) {
  185. // CHECK:STDOUT: %T.loc19_23.2 => constants.%T
  186. // CHECK:STDOUT: %GenericInterface.type.loc19_52.2 => constants.%GenericInterface.type.2
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: !definition:
  189. // CHECK:STDOUT: %F.type => constants.%F.type.2
  190. // CHECK:STDOUT: %F => constants.%F.2
  191. // CHECK:STDOUT: %.loc19_56.2 => constants.%.4
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: specific @F.2(constants.%T) {
  195. // CHECK:STDOUT: %T => constants.%T
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: specific @F.1(constants.%T, constants.%C) {
  199. // CHECK:STDOUT: %T => constants.%T
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: specific @impl(@impl.%T.loc19_23.2) {
  203. // CHECK:STDOUT: %T.loc19_23.2 => constants.%T
  204. // CHECK:STDOUT: %GenericInterface.type.loc19_52.2 => constants.%GenericInterface.type.2
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT: