fail_extend_impl_forall.carbon 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: type = generic_interface_type @GenericInterface [template]
  26. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  27. // CHECK:STDOUT: %GenericInterface: %GenericInterface.type = struct_value () [template]
  28. // CHECK:STDOUT: %.2: type = interface_type @GenericInterface, @GenericInterface(%T) [symbolic]
  29. // CHECK:STDOUT: %Self: %.2 = bind_symbolic_name Self 1 [symbolic]
  30. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  31. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  32. // CHECK:STDOUT: %.3: type = assoc_entity_type @GenericInterface, %F.type.1 [template]
  33. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @GenericInterface.%F.decl [template]
  34. // CHECK:STDOUT: %C: type = class_type @C [template]
  35. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  36. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  37. // CHECK:STDOUT: %.5: <witness> = interface_witness (%F.2) [template]
  38. // CHECK:STDOUT: %.6: type = struct_type {} [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = %Core
  44. // CHECK:STDOUT: .GenericInterface = %GenericInterface.decl
  45. // CHECK:STDOUT: .C = %C.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  49. // CHECK:STDOUT: import Core//prelude
  50. // CHECK:STDOUT: import Core//prelude/operators
  51. // CHECK:STDOUT: import Core//prelude/types
  52. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  53. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  54. // CHECK:STDOUT: import Core//prelude/operators/comparison
  55. // CHECK:STDOUT: import Core//prelude/types/bool
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %GenericInterface.decl: %GenericInterface.type = interface_decl @GenericInterface [template = constants.%GenericInterface] {
  58. // CHECK:STDOUT: %T.loc11_28.1: type = param T
  59. // CHECK:STDOUT: %T.loc11_28.2: type = bind_symbolic_name T 0, %T.loc11_28.1 [symbolic = @GenericInterface.%T (constants.%T)]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: generic interface @GenericInterface(file.%T.loc11_28.2: type) {
  65. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !definition:
  68. // CHECK:STDOUT: %.1: type = interface_type @GenericInterface, @GenericInterface(%T) [symbolic = %.1 (constants.%.2)]
  69. // CHECK:STDOUT: %Self.2: %.2 = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: interface {
  72. // CHECK:STDOUT: %Self.1: @GenericInterface.%.1 (%.2) = bind_symbolic_name Self 1 [symbolic = %Self.2 (constants.%Self)]
  73. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {
  74. // CHECK:STDOUT: %T.ref: type = name_ref T, file.%T.loc11_28.2 [symbolic = @F.1.%T (constants.%T)]
  75. // CHECK:STDOUT: %x.loc12_8.1: @F.1.%T (%T) = param x
  76. // CHECK:STDOUT: %x.loc12_8.2: @F.1.%T (%T) = bind_name x, %x.loc12_8.1
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %.loc12: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = %Self.1
  82. // CHECK:STDOUT: .F = %.loc12
  83. // CHECK:STDOUT: witness = (%F.decl)
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: impl @impl: %C as %.2 {
  88. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  89. // CHECK:STDOUT: %T.ref: type = name_ref T, @C.%T.loc19_23.2 [symbolic = @F.2.%T (constants.%T)]
  90. // CHECK:STDOUT: %x.loc20_10.1: @F.2.%T (%T) = param x
  91. // CHECK:STDOUT: %x.loc20_10.2: @F.2.%T (%T) = bind_name x, %x.loc20_10.1
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .F = %F.decl
  97. // CHECK:STDOUT: witness = %.1
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: class @C {
  101. // CHECK:STDOUT: %.loc19_54.1: type = value_of_initializer %.loc19_52 [symbolic = constants.%.2]
  102. // CHECK:STDOUT: %.loc19_54.2: type = converted %.loc19_52, %.loc19_54.1 [symbolic = constants.%.2]
  103. // CHECK:STDOUT: impl_decl @impl {
  104. // CHECK:STDOUT: %T.loc19_23.1: type = param T
  105. // CHECK:STDOUT: %T.loc19_23.2: type = bind_symbolic_name T 0, %T.loc19_23.1 [symbolic = constants.%T]
  106. // CHECK:STDOUT: %GenericInterface.ref: %GenericInterface.type = name_ref GenericInterface, file.%GenericInterface.decl [template = constants.%GenericInterface]
  107. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc19_23.2 [symbolic = constants.%T]
  108. // CHECK:STDOUT: %.loc19_52: init type = call %GenericInterface.ref(%T.ref) [symbolic = constants.%.2]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: !members:
  112. // CHECK:STDOUT: .Self = constants.%C
  113. // CHECK:STDOUT: has_error
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: generic fn @F.1(file.%T.loc11_28.2: type, @GenericInterface.%Self.1: @GenericInterface.%.1 (%.2)) {
  117. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn(@GenericInterface.%x.loc12_8.2: @F.1.%T (%T));
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: generic fn @F.2(@C.%T.loc19_23.2: type) {
  123. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic = %T (constants.%T)]
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: !definition:
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: fn(@impl.%x.loc20_10.2: @F.2.%T (%T)) {
  128. // CHECK:STDOUT: !entry:
  129. // CHECK:STDOUT: return
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: specific @GenericInterface(constants.%T) {
  134. // CHECK:STDOUT: %T => constants.%T
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: specific @F.1(constants.%T, constants.%Self) {
  138. // CHECK:STDOUT: %T => constants.%T
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: specific @GenericInterface(@GenericInterface.%T) {
  142. // CHECK:STDOUT: %T => constants.%T
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: specific @F.2(constants.%T) {
  146. // CHECK:STDOUT: %T => constants.%T
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: