fail_generic_method.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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/class/fail_generic_method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_generic_method.carbon
  10. class Class(T:! type) {
  11. var a: T;
  12. fn F[self: Self](n: T);
  13. }
  14. // TODO: The follow-on errors here aren't great. Investigate whether we can
  15. // enter the scope anyway if the parameters don't match.
  16. // CHECK:STDERR: fail_generic_method.carbon:[[@LINE+14]]:10: error: redeclaration differs at parameter 1 [RedeclParamDiffers]
  17. // CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
  18. // CHECK:STDERR: ^~~~~~~
  19. // CHECK:STDERR: fail_generic_method.carbon:[[@LINE-10]]:13: note: previous declaration's corresponding parameter here [RedeclParamPrevious]
  20. // CHECK:STDERR: class Class(T:! type) {
  21. // CHECK:STDERR: ^~~~~~~~
  22. // CHECK:STDERR:
  23. // CHECK:STDERR: fail_generic_method.carbon:[[@LINE+7]]:27: error: name `Self` not found [NameNotFound]
  24. // CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
  25. // CHECK:STDERR: ^~~~
  26. // CHECK:STDERR:
  27. // CHECK:STDERR: fail_generic_method.carbon:[[@LINE+3]]:36: error: name `T` not found [NameNotFound]
  28. // CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
  29. // CHECK:STDERR: ^
  30. fn Class(N:! i32).F[self: Self](n: T) {}
  31. // CHECK:STDOUT: --- fail_generic_method.carbon
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: constants {
  34. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  35. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  36. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [template]
  37. // CHECK:STDOUT: %Class.1: %Class.type = struct_value () [template]
  38. // CHECK:STDOUT: %Class.2: type = class_type @Class, @Class(%T) [symbolic]
  39. // CHECK:STDOUT: %.1: type = unbound_element_type %Class.2, %T [symbolic]
  40. // CHECK:STDOUT: %F.type: type = fn_type @F, @Class(%T) [symbolic]
  41. // CHECK:STDOUT: %F: %F.type = struct_value () [symbolic]
  42. // CHECK:STDOUT: %.2: type = struct_type {.a: %T} [symbolic]
  43. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [symbolic]
  44. // CHECK:STDOUT: %.4: Core.IntLiteral = int_value 32 [template]
  45. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  46. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  47. // CHECK:STDOUT: %i32: type = int_type signed, %.4 [template]
  48. // CHECK:STDOUT: %N: %i32 = bind_symbolic_name N, 0 [symbolic]
  49. // CHECK:STDOUT: %N.patt: %i32 = symbolic_binding_pattern N, 0 [symbolic]
  50. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  51. // CHECK:STDOUT: %.5: %.type = struct_value () [template]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  56. // CHECK:STDOUT: .Int = %import_ref
  57. // CHECK:STDOUT: import Core//prelude
  58. // CHECK:STDOUT: import Core//prelude/...
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .Class = %Class.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  69. // CHECK:STDOUT: %T.patt.loc11_13.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc11_13.2 (constants.%T.patt)]
  70. // CHECK:STDOUT: %T.param_patt: type = value_param_pattern %T.patt.loc11_13.1, runtime_param<invalid> [symbolic = %T.patt.loc11_13.2 (constants.%T.patt)]
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %T.param: type = value_param runtime_param<invalid>
  73. // CHECK:STDOUT: %T.loc11_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc11_13.2 (constants.%T)]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.5] {
  76. // CHECK:STDOUT: %self.patt: <error> = binding_pattern self
  77. // CHECK:STDOUT: %self.param_patt: <error> = value_param_pattern %self.patt, runtime_param0
  78. // CHECK:STDOUT: %n.patt: <error> = binding_pattern n
  79. // CHECK:STDOUT: %n.param_patt: <error> = value_param_pattern %n.patt, runtime_param1
  80. // CHECK:STDOUT: } {
  81. // CHECK:STDOUT: %.loc32_14.1: Core.IntLiteral = int_value 32 [template = constants.%.4]
  82. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc32_14.1) [template = constants.%i32]
  83. // CHECK:STDOUT: %.loc32_14.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  84. // CHECK:STDOUT: %.loc32_14.3: type = converted %int.make_type_signed, %.loc32_14.2 [template = constants.%i32]
  85. // CHECK:STDOUT: %N.param: %i32 = value_param runtime_param<invalid>
  86. // CHECK:STDOUT: %N.loc32_10.1: %i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc32_10.2 (constants.%N)]
  87. // CHECK:STDOUT: %Self.ref: <error> = name_ref Self, <error> [template = <error>]
  88. // CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [template = <error>]
  89. // CHECK:STDOUT: %self.param: <error> = value_param runtime_param0
  90. // CHECK:STDOUT: %self: <error> = bind_name self, %self.param
  91. // CHECK:STDOUT: %n.param: <error> = value_param runtime_param1
  92. // CHECK:STDOUT: %n: <error> = bind_name n, %n.param
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: generic class @Class(%T.loc11_13.1: type) {
  97. // CHECK:STDOUT: %T.loc11_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_13.2 (constants.%T)]
  98. // CHECK:STDOUT: %T.patt.loc11_13.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc11_13.2 (constants.%T.patt)]
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: !definition:
  101. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T.loc11_13.2) [symbolic = %Class (constants.%Class.2)]
  102. // CHECK:STDOUT: %.loc12_8.2: type = unbound_element_type @Class.%Class (%Class.2), @Class.%T.loc11_13.2 (%T) [symbolic = %.loc12_8.2 (constants.%.1)]
  103. // CHECK:STDOUT: %F.type: type = fn_type @F, @Class(%T.loc11_13.2) [symbolic = %F.type (constants.%F.type)]
  104. // CHECK:STDOUT: %F: @Class.%F.type (%F.type) = struct_value () [symbolic = %F (constants.%F)]
  105. // CHECK:STDOUT: %.loc14_1.2: type = struct_type {.a: @Class.%T.loc11_13.2 (%T)} [symbolic = %.loc14_1.2 (constants.%.2)]
  106. // CHECK:STDOUT: %.loc14_1.3: <witness> = complete_type_witness @Class.%.loc14_1.2 (%.2) [symbolic = %.loc14_1.3 (constants.%.3)]
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: class {
  109. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc11_13.1 [symbolic = %T.loc11_13.2 (constants.%T)]
  110. // CHECK:STDOUT: %.loc12_8.1: @Class.%.loc12_8.2 (%.1) = field_decl a, element0 [template]
  111. // CHECK:STDOUT: %F.decl: @Class.%F.type (%F.type) = fn_decl @F [symbolic = @Class.%F (constants.%F)] {
  112. // CHECK:STDOUT: %self.patt: @F.%Class (%Class.2) = binding_pattern self
  113. // CHECK:STDOUT: %self.param_patt: @F.%Class (%Class.2) = value_param_pattern %self.patt, runtime_param0
  114. // CHECK:STDOUT: %n.patt: @F.%T (%T) = binding_pattern n
  115. // CHECK:STDOUT: %n.param_patt: @F.%T (%T) = value_param_pattern %n.patt, runtime_param1
  116. // CHECK:STDOUT: } {
  117. // CHECK:STDOUT: %.loc13: type = specific_constant constants.%Class.2, @Class(constants.%T) [symbolic = %Class (constants.%Class.2)]
  118. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc13 [symbolic = %Class (constants.%Class.2)]
  119. // CHECK:STDOUT: %T.ref: type = name_ref T, @Class.%T.loc11_13.1 [symbolic = %T (constants.%T)]
  120. // CHECK:STDOUT: %self.param: @F.%Class (%Class.2) = value_param runtime_param0
  121. // CHECK:STDOUT: %self: @F.%Class (%Class.2) = bind_name self, %self.param
  122. // CHECK:STDOUT: %n.param: @F.%T (%T) = value_param runtime_param1
  123. // CHECK:STDOUT: %n: @F.%T (%T) = bind_name n, %n.param
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: %.loc14_1.1: <witness> = complete_type_witness %.2 [symbolic = %.loc14_1.3 (constants.%.3)]
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = constants.%Class.2
  129. // CHECK:STDOUT: .a = %.loc12_8.1
  130. // CHECK:STDOUT: .F = %F.decl
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: generic fn @F(@Class.%T.loc11_13.1: type) {
  135. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  136. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class.2)]
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: fn[%self.param_patt: @F.%Class (%Class.2)](%n.param_patt: @F.%T (%T));
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: generic fn @.1(%N.loc32_10.1: %i32) {
  142. // CHECK:STDOUT: %N.loc32_10.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc32_10.2 (constants.%N)]
  143. // CHECK:STDOUT: %N.patt: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt (constants.%N.patt)]
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: !definition:
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: fn[%self.param_patt: <error>](%n.param_patt: <error>) {
  148. // CHECK:STDOUT: !entry:
  149. // CHECK:STDOUT: return
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: specific @Class(constants.%T) {
  154. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  155. // CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: specific @Class(@F.%T) {
  159. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  160. // CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: specific @F(constants.%T) {
  164. // CHECK:STDOUT: %T => constants.%T
  165. // CHECK:STDOUT: %Class => constants.%Class.2
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: specific @Class(%T.loc11_13.2) {
  169. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  170. // CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: specific @.1(constants.%N) {
  174. // CHECK:STDOUT: %N.loc32_10.2 => constants.%N
  175. // CHECK:STDOUT: %N.patt => constants.%N
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: