fail_generic_method.carbon 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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
  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
  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
  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
  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: %Class.type: type = generic_class_type @Class [template]
  36. // CHECK:STDOUT: %.1: type = tuple_type () [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: %.2: 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: %.3: type = struct_type {.a: %T} [symbolic]
  43. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [symbolic]
  44. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  45. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  46. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N, 0 [symbolic]
  47. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  48. // CHECK:STDOUT: %.5: %.type = struct_value () [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  53. // CHECK:STDOUT: .Int32 = %import_ref
  54. // CHECK:STDOUT: import Core//prelude
  55. // CHECK:STDOUT: import Core//prelude/operators
  56. // CHECK:STDOUT: import Core//prelude/types
  57. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  58. // CHECK:STDOUT: import Core//prelude/operators/as
  59. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  60. // CHECK:STDOUT: import Core//prelude/operators/comparison
  61. // CHECK:STDOUT: import Core//prelude/types/bool
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  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: .Class = %Class.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.import = import Core
  72. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [template = constants.%Class.1] {
  73. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0
  74. // CHECK:STDOUT: } {
  75. // CHECK:STDOUT: %T.param: type = param T, runtime_param<invalid>
  76. // CHECK:STDOUT: %T.loc11_13.1: type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc11_13.2 (constants.%T)]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.5] {
  79. // CHECK:STDOUT: %self.patt: <error> = binding_pattern self
  80. // CHECK:STDOUT: %n.patt: <error> = binding_pattern n
  81. // CHECK:STDOUT: } {
  82. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  83. // CHECK:STDOUT: %.loc32_14.1: type = value_of_initializer %int.make_type_32 [template = i32]
  84. // CHECK:STDOUT: %.loc32_14.2: type = converted %int.make_type_32, %.loc32_14.1 [template = i32]
  85. // CHECK:STDOUT: %N.param: i32 = param N, 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: %self.param: <error> = param self, runtime_param0
  89. // CHECK:STDOUT: %self: <error> = bind_name self, %self.param
  90. // CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [template = <error>]
  91. // CHECK:STDOUT: %n.param: <error> = param n, 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:
  99. // CHECK:STDOUT: !definition:
  100. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T.loc11_13.2) [symbolic = %Class (constants.%Class.2)]
  101. // CHECK:STDOUT: %.loc12_8.2: type = unbound_element_type @Class.%Class (%Class.2), @Class.%T.loc11_13.2 (%T) [symbolic = %.loc12_8.2 (constants.%.2)]
  102. // CHECK:STDOUT: %F.type: type = fn_type @F, @Class(%T.loc11_13.2) [symbolic = %F.type (constants.%F.type)]
  103. // CHECK:STDOUT: %F: @Class.%F.type (%F.type) = struct_value () [symbolic = %F (constants.%F)]
  104. // CHECK:STDOUT: %.loc14_1.2: type = struct_type {.a: @Class.%T.loc11_13.2 (%T)} [symbolic = %.loc14_1.2 (constants.%.3)]
  105. // CHECK:STDOUT: %.loc14_1.3: <witness> = complete_type_witness @Class.%.loc14_1.2 (%.3) [symbolic = %.loc14_1.3 (constants.%.4)]
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: class {
  108. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc11_13.1 [symbolic = %T.loc11_13.2 (constants.%T)]
  109. // CHECK:STDOUT: %.loc12_8.1: @Class.%.loc12_8.2 (%.2) = field_decl a, element0 [template]
  110. // CHECK:STDOUT: %F.decl: @Class.%F.type (%F.type) = fn_decl @F [symbolic = @Class.%F (constants.%F)] {
  111. // CHECK:STDOUT: %self.patt: @F.%Class (%Class.2) = binding_pattern self
  112. // CHECK:STDOUT: %n.patt: @F.%T (%T) = binding_pattern n
  113. // CHECK:STDOUT: } {
  114. // CHECK:STDOUT: %.loc13: type = specific_constant constants.%Class.2, @Class(constants.%T) [symbolic = %Class (constants.%Class.2)]
  115. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc13 [symbolic = %Class (constants.%Class.2)]
  116. // CHECK:STDOUT: %self.param: @F.%Class (%Class.2) = param self, runtime_param0
  117. // CHECK:STDOUT: %self: @F.%Class (%Class.2) = bind_name self, %self.param
  118. // CHECK:STDOUT: %T.ref: type = name_ref T, @Class.%T.loc11_13.1 [symbolic = %T (constants.%T)]
  119. // CHECK:STDOUT: %n.param: @F.%T (%T) = param n, runtime_param1
  120. // CHECK:STDOUT: %n: @F.%T (%T) = bind_name n, %n.param
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %.loc14_1.1: <witness> = complete_type_witness %.3 [symbolic = %.loc14_1.3 (constants.%.4)]
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: !members:
  125. // CHECK:STDOUT: .Self = constants.%Class.2
  126. // CHECK:STDOUT: .a = %.loc12_8.1
  127. // CHECK:STDOUT: .F = %F.decl
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: generic fn @F(@Class.%T.loc11_13.1: type) {
  132. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  133. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class.2)]
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: fn[%self: @F.%Class (%Class.2)](%n: @F.%T (%T));
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: generic fn @.1(%N.loc32_10.1: i32) {
  141. // CHECK:STDOUT: %N.loc32_10.2: i32 = bind_symbolic_name N, 0 [symbolic = %N.loc32_10.2 (constants.%N)]
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: !definition:
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn[%self: <error>](%n: <error>) {
  146. // CHECK:STDOUT: !entry:
  147. // CHECK:STDOUT: return
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: specific @Class(constants.%T) {
  152. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: specific @Class(@F.%T) {
  156. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: specific @F(constants.%T) {
  160. // CHECK:STDOUT: %T => constants.%T
  161. // CHECK:STDOUT: %Class => constants.%Class.2
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: specific @Class(@Class.%T.loc11_13.2) {
  165. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: specific @.1(constants.%N) {
  169. // CHECK:STDOUT: %N.loc32_10.2 => constants.%N
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT: