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+15]]:10: error: type `i32` of parameter 1 in redeclaration differs from previous parameter type `type` [RedeclParamDiffersType]
  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+8]]: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+4]]:36: error: name `T` not found [NameNotFound]
  28. // CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
  29. // CHECK:STDERR: ^
  30. // CHECK:STDERR:
  31. fn Class(N:! i32).F[self: Self](n: T) {}
  32. // CHECK:STDOUT: --- fail_generic_method.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  36. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0 [symbolic]
  37. // CHECK:STDOUT: %Class.type: type = generic_class_type @Class [concrete]
  38. // CHECK:STDOUT: %Class.generic: %Class.type = struct_value () [concrete]
  39. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic]
  40. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [symbolic]
  41. // CHECK:STDOUT: %Class.elem: type = unbound_element_type %Class, %T [symbolic]
  42. // CHECK:STDOUT: %F.type: type = fn_type @F, @Class(%T) [symbolic]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [symbolic]
  44. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %T} [symbolic]
  45. // CHECK:STDOUT: %complete_type.f1b: <witness> = complete_type_witness %struct_type.a [symbolic]
  46. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  47. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  48. // CHECK:STDOUT: %N.51e: %i32 = bind_symbolic_name N, 0 [symbolic]
  49. // CHECK:STDOUT: %N.patt.8e2: %i32 = symbolic_binding_pattern N, 0 [symbolic]
  50. // CHECK:STDOUT: %.type: type = fn_type @.1 [concrete]
  51. // CHECK:STDOUT: %.d85: %.type = struct_value () [concrete]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  56. // CHECK:STDOUT: .Int = %Core.Int
  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 [concrete] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .Class = %Class.decl
  66. // CHECK:STDOUT: .T = <poisoned>
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core.import = import Core
  69. // CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [concrete = constants.%Class.generic] {
  70. // CHECK:STDOUT: %T.patt.loc11_13.1: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc11_13.2 (constants.%T.patt)]
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %T.loc11_13.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_13.2 (constants.%T)]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [concrete = constants.%.d85] {
  75. // CHECK:STDOUT: %self.patt: <error> = binding_pattern self
  76. // CHECK:STDOUT: %self.param_patt: <error> = value_param_pattern %self.patt, call_param0 [concrete = <error>]
  77. // CHECK:STDOUT: %n.patt: <error> = binding_pattern n
  78. // CHECK:STDOUT: %n.param_patt: <error> = value_param_pattern %n.patt, call_param1 [concrete = <error>]
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %.loc33: type = splice_block %i32 [concrete = constants.%i32] {
  81. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  82. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %N.loc33_10.1: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc33_10.2 (constants.%N.51e)]
  85. // CHECK:STDOUT: %self.param: <error> = value_param call_param0
  86. // CHECK:STDOUT: %Self.ref: <error> = name_ref Self, <error> [concrete = <error>]
  87. // CHECK:STDOUT: %self: <error> = bind_name self, %self.param
  88. // CHECK:STDOUT: %n.param: <error> = value_param call_param1
  89. // CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [concrete = <error>]
  90. // CHECK:STDOUT: %n: <error> = bind_name n, %n.param
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic class @Class(%T.loc11_13.1: type) {
  95. // CHECK:STDOUT: %T.loc11_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc11_13.2 (constants.%T)]
  96. // CHECK:STDOUT: %T.patt.loc11_13.2: type = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc11_13.2 (constants.%T.patt)]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !definition:
  99. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @Class.%T.loc11_13.2 (%T) [symbolic = %require_complete (constants.%require_complete.4ae)]
  100. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T.loc11_13.2) [symbolic = %Class (constants.%Class)]
  101. // CHECK:STDOUT: %Class.elem: type = unbound_element_type @Class.%Class (%Class), @Class.%T.loc11_13.2 (%T) [symbolic = %Class.elem (constants.%Class.elem)]
  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: %struct_type.a: type = struct_type {.a: @Class.%T.loc11_13.2 (%T)} [symbolic = %struct_type.a (constants.%struct_type.a)]
  105. // CHECK:STDOUT: %complete_type.loc14_1.2: <witness> = complete_type_witness @Class.%struct_type.a (%struct_type.a) [symbolic = %complete_type.loc14_1.2 (constants.%complete_type.f1b)]
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: class {
  108. // CHECK:STDOUT: %.loc12_8: @Class.%Class.elem (%Class.elem) = field_decl a, element0 [concrete]
  109. // CHECK:STDOUT: name_binding_decl {
  110. // CHECK:STDOUT: %.loc12_3: @Class.%Class.elem (%Class.elem) = var_pattern %.loc12_8
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %.var: ref @Class.%Class.elem (%Class.elem) = var <none>
  113. // CHECK:STDOUT: %F.decl: @Class.%F.type (%F.type) = fn_decl @F [symbolic = @Class.%F (constants.%F)] {
  114. // CHECK:STDOUT: %self.patt: @F.%Class (%Class) = binding_pattern self
  115. // CHECK:STDOUT: %self.param_patt: @F.%Class (%Class) = value_param_pattern %self.patt, call_param0
  116. // CHECK:STDOUT: %n.patt: @F.%T (%T) = binding_pattern n
  117. // CHECK:STDOUT: %n.param_patt: @F.%T (%T) = value_param_pattern %n.patt, call_param1
  118. // CHECK:STDOUT: } {
  119. // CHECK:STDOUT: %self.param: @F.%Class (%Class) = value_param call_param0
  120. // CHECK:STDOUT: %.loc13_14.1: type = splice_block %Self.ref [symbolic = %Class (constants.%Class)] {
  121. // CHECK:STDOUT: %.loc13_14.2: type = specific_constant constants.%Class, @Class(constants.%T) [symbolic = %Class (constants.%Class)]
  122. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc13_14.2 [symbolic = %Class (constants.%Class)]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %self: @F.%Class (%Class) = bind_name self, %self.param
  125. // CHECK:STDOUT: %n.param: @F.%T (%T) = value_param call_param1
  126. // CHECK:STDOUT: %T.ref: type = name_ref T, @Class.%T.loc11_13.1 [symbolic = %T (constants.%T)]
  127. // CHECK:STDOUT: %n: @F.%T (%T) = bind_name n, %n.param
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %complete_type.loc14_1.1: <witness> = complete_type_witness %struct_type.a [symbolic = %complete_type.loc14_1.2 (constants.%complete_type.f1b)]
  130. // CHECK:STDOUT: complete_type_witness = %complete_type.loc14_1.1
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: !members:
  133. // CHECK:STDOUT: .Self = constants.%Class
  134. // CHECK:STDOUT: .T = <poisoned>
  135. // CHECK:STDOUT: .a = %.loc12_8
  136. // CHECK:STDOUT: .F = %F.decl
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: generic fn @F(@Class.%T.loc11_13.1: type) {
  141. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  142. // CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class)]
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: fn[%self.param_patt: @F.%Class (%Class)](%n.param_patt: @F.%T (%T));
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: generic fn @.1(%N.loc33_10.1: %i32) {
  148. // CHECK:STDOUT: %N.loc33_10.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc33_10.2 (constants.%N.51e)]
  149. // CHECK:STDOUT: %N.patt: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt (constants.%N.patt.8e2)]
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: !definition:
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: fn[%self.param_patt: <error>](%n.param_patt: <error>) {
  154. // CHECK:STDOUT: !entry:
  155. // CHECK:STDOUT: return
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: specific @Class(constants.%T) {
  160. // CHECK:STDOUT: %T.loc11_13.2 => constants.%T
  161. // CHECK:STDOUT: %T.patt.loc11_13.2 => constants.%T
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: specific @F(constants.%T) {
  165. // CHECK:STDOUT: %T => constants.%T
  166. // CHECK:STDOUT: %Class => constants.%Class
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: specific @Class(@F.%T) {}
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: specific @Class(%T.loc11_13.2) {}
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: specific @.1(constants.%N.51e) {
  174. // CHECK:STDOUT: %N.loc33_10.2 => constants.%N.51e
  175. // CHECK:STDOUT: %N.patt => constants.%N.51e
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: