fail_decl_param_mismatch.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --no-prelude-import --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/definition/fail_decl_param_mismatch.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/definition/fail_decl_param_mismatch.carbon
  13. fn F();
  14. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE+7]]:1: error: redeclaration differs because of parameter count of 1 [RedeclParamCountDiffers]
  15. // CHECK:STDERR: fn F(x: ()) {}
  16. // CHECK:STDERR: ^~~~~~~~~~~~~
  17. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE-4]]:1: note: previously declared with parameter count of 0 [RedeclParamCountPrevious]
  18. // CHECK:STDERR: fn F();
  19. // CHECK:STDERR: ^~~~~~~
  20. // CHECK:STDERR:
  21. fn F(x: ()) {}
  22. fn G(x: ());
  23. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE+7]]:1: error: redeclaration differs because of parameter count of 0 [RedeclParamCountDiffers]
  24. // CHECK:STDERR: fn G() {}
  25. // CHECK:STDERR: ^~~~~~~~
  26. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE-4]]:1: note: previously declared with parameter count of 1 [RedeclParamCountPrevious]
  27. // CHECK:STDERR: fn G(x: ());
  28. // CHECK:STDERR: ^~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. fn G() {}
  31. fn H(x: ());
  32. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE+4]]:9: error: `Core.Bool` implicitly referenced here, but package `Core` not found [CoreNotFound]
  33. // CHECK:STDERR: fn H(x: bool) {}
  34. // CHECK:STDERR: ^~~~
  35. // CHECK:STDERR:
  36. fn H(x: bool) {}
  37. fn I();
  38. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE+7]]:1: error: function redeclaration differs because return type is `()` [FunctionRedeclReturnTypeDiffers]
  39. // CHECK:STDERR: fn I() -> () { return (); }
  40. // CHECK:STDERR: ^~~~~~~~~~~~~~
  41. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE-4]]:1: note: previously declared with no return type [FunctionRedeclReturnTypePreviousNoReturn]
  42. // CHECK:STDERR: fn I();
  43. // CHECK:STDERR: ^~~~~~~
  44. // CHECK:STDERR:
  45. fn I() -> () { return (); }
  46. fn J() -> ();
  47. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE+7]]:1: error: function redeclaration differs because no return type is provided [FunctionRedeclReturnTypeDiffersNoReturn]
  48. // CHECK:STDERR: fn J() {}
  49. // CHECK:STDERR: ^~~~~~~~
  50. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE-4]]:1: note: previously declared with return type `()` [FunctionRedeclReturnTypePrevious]
  51. // CHECK:STDERR: fn J() -> ();
  52. // CHECK:STDERR: ^~~~~~~~~~~~~
  53. // CHECK:STDERR:
  54. fn J() {}
  55. fn K() -> ();
  56. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE+7]]:1: error: function redeclaration differs because return type is `{}` [FunctionRedeclReturnTypeDiffers]
  57. // CHECK:STDERR: fn K() -> {} { return {}; }
  58. // CHECK:STDERR: ^~~~~~~~~~~~~~
  59. // CHECK:STDERR: fail_decl_param_mismatch.carbon:[[@LINE-4]]:1: note: previously declared with return type `()` [FunctionRedeclReturnTypePrevious]
  60. // CHECK:STDERR: fn K() -> ();
  61. // CHECK:STDERR: ^~~~~~~~~~~~~
  62. // CHECK:STDERR:
  63. fn K() -> {} { return {}; }
  64. // CHECK:STDOUT: --- fail_decl_param_mismatch.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %F.type.b25846.1: type = fn_type @F.1 [concrete]
  68. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  69. // CHECK:STDOUT: %F.c41931.1: %F.type.b25846.1 = struct_value () [concrete]
  70. // CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
  71. // CHECK:STDOUT: %F.type.b25846.2: type = fn_type @F.2 [concrete]
  72. // CHECK:STDOUT: %F.c41931.2: %F.type.b25846.2 = struct_value () [concrete]
  73. // CHECK:STDOUT: %G.type.9f9306.1: type = fn_type @G.1 [concrete]
  74. // CHECK:STDOUT: %G.57b67a.1: %G.type.9f9306.1 = struct_value () [concrete]
  75. // CHECK:STDOUT: %G.type.9f9306.2: type = fn_type @G.2 [concrete]
  76. // CHECK:STDOUT: %G.57b67a.2: %G.type.9f9306.2 = struct_value () [concrete]
  77. // CHECK:STDOUT: %H.type.6826c6.1: type = fn_type @H.1 [concrete]
  78. // CHECK:STDOUT: %H.8a6545.1: %H.type.6826c6.1 = struct_value () [concrete]
  79. // CHECK:STDOUT: %H.type.6826c6.2: type = fn_type @H.2 [concrete]
  80. // CHECK:STDOUT: %H.8a6545.2: %H.type.6826c6.2 = struct_value () [concrete]
  81. // CHECK:STDOUT: %I.type.af49c4.1: type = fn_type @I.1 [concrete]
  82. // CHECK:STDOUT: %I.58e4ec.1: %I.type.af49c4.1 = struct_value () [concrete]
  83. // CHECK:STDOUT: %I.type.af49c4.2: type = fn_type @I.2 [concrete]
  84. // CHECK:STDOUT: %I.58e4ec.2: %I.type.af49c4.2 = struct_value () [concrete]
  85. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  86. // CHECK:STDOUT: %J.type.8e2c84.1: type = fn_type @J.1 [concrete]
  87. // CHECK:STDOUT: %J.3662e8.1: %J.type.8e2c84.1 = struct_value () [concrete]
  88. // CHECK:STDOUT: %J.type.8e2c84.2: type = fn_type @J.2 [concrete]
  89. // CHECK:STDOUT: %J.3662e8.2: %J.type.8e2c84.2 = struct_value () [concrete]
  90. // CHECK:STDOUT: %K.type.6cc1c5.1: type = fn_type @K.1 [concrete]
  91. // CHECK:STDOUT: %K.460d95.1: %K.type.6cc1c5.1 = struct_value () [concrete]
  92. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  93. // CHECK:STDOUT: %pattern_type.a96: type = pattern_type %empty_struct_type [concrete]
  94. // CHECK:STDOUT: %K.type.6cc1c5.2: type = fn_type @K.2 [concrete]
  95. // CHECK:STDOUT: %K.460d95.2: %K.type.6cc1c5.2 = struct_value () [concrete]
  96. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: file {
  100. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  101. // CHECK:STDOUT: .F = %F.decl.loc14
  102. // CHECK:STDOUT: .G = %G.decl.loc24
  103. // CHECK:STDOUT: .H = %H.decl.loc34
  104. // CHECK:STDOUT: .I = %I.decl.loc41
  105. // CHECK:STDOUT: .J = %J.decl.loc51
  106. // CHECK:STDOUT: .K = %K.decl.loc61
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %F.decl.loc14: %F.type.b25846.1 = fn_decl @F.1 [concrete = constants.%F.c41931.1] {} {}
  109. // CHECK:STDOUT: %F.decl.loc22: %F.type.b25846.2 = fn_decl @F.2 [concrete = constants.%F.c41931.2] {
  110. // CHECK:STDOUT: %x.patt: %pattern_type.cb1 = binding_pattern x [concrete]
  111. // CHECK:STDOUT: %x.param_patt: %pattern_type.cb1 = value_param_pattern %x.patt, call_param0 [concrete]
  112. // CHECK:STDOUT: } {
  113. // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param call_param0
  114. // CHECK:STDOUT: %.loc22_10.1: type = splice_block %.loc22_10.3 [concrete = constants.%empty_tuple.type] {
  115. // CHECK:STDOUT: %.loc22_10.2: %empty_tuple.type = tuple_literal ()
  116. // CHECK:STDOUT: %.loc22_10.3: type = converted %.loc22_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %x: %empty_tuple.type = bind_name x, %x.param
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %G.decl.loc24: %G.type.9f9306.1 = fn_decl @G.1 [concrete = constants.%G.57b67a.1] {
  121. // CHECK:STDOUT: %x.patt: %pattern_type.cb1 = binding_pattern x [concrete]
  122. // CHECK:STDOUT: %x.param_patt: %pattern_type.cb1 = value_param_pattern %x.patt, call_param0 [concrete]
  123. // CHECK:STDOUT: } {
  124. // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param call_param0
  125. // CHECK:STDOUT: %.loc24_10.1: type = splice_block %.loc24_10.3 [concrete = constants.%empty_tuple.type] {
  126. // CHECK:STDOUT: %.loc24_10.2: %empty_tuple.type = tuple_literal ()
  127. // CHECK:STDOUT: %.loc24_10.3: type = converted %.loc24_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %x: %empty_tuple.type = bind_name x, %x.param
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %G.decl.loc32: %G.type.9f9306.2 = fn_decl @G.2 [concrete = constants.%G.57b67a.2] {} {}
  132. // CHECK:STDOUT: %H.decl.loc34: %H.type.6826c6.1 = fn_decl @H.1 [concrete = constants.%H.8a6545.1] {
  133. // CHECK:STDOUT: %x.patt: %pattern_type.cb1 = binding_pattern x [concrete]
  134. // CHECK:STDOUT: %x.param_patt: %pattern_type.cb1 = value_param_pattern %x.patt, call_param0 [concrete]
  135. // CHECK:STDOUT: } {
  136. // CHECK:STDOUT: %x.param: %empty_tuple.type = value_param call_param0
  137. // CHECK:STDOUT: %.loc34_10.1: type = splice_block %.loc34_10.3 [concrete = constants.%empty_tuple.type] {
  138. // CHECK:STDOUT: %.loc34_10.2: %empty_tuple.type = tuple_literal ()
  139. // CHECK:STDOUT: %.loc34_10.3: type = converted %.loc34_10.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %x: %empty_tuple.type = bind_name x, %x.param
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %H.decl.loc39: %H.type.6826c6.2 = fn_decl @H.2 [concrete = constants.%H.8a6545.2] {
  144. // CHECK:STDOUT: %x.patt: <error> = binding_pattern x [concrete]
  145. // CHECK:STDOUT: %x.param_patt: <error> = value_param_pattern %x.patt, call_param0 [concrete]
  146. // CHECK:STDOUT: } {
  147. // CHECK:STDOUT: %x.param: <error> = value_param call_param0
  148. // CHECK:STDOUT: %x: <error> = bind_name x, %x.param [concrete = <error>]
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: %I.decl.loc41: %I.type.af49c4.1 = fn_decl @I.1 [concrete = constants.%I.58e4ec.1] {} {}
  151. // CHECK:STDOUT: %I.decl.loc49: %I.type.af49c4.2 = fn_decl @I.2 [concrete = constants.%I.58e4ec.2] {
  152. // CHECK:STDOUT: %return.patt: %pattern_type.cb1 = return_slot_pattern [concrete]
  153. // CHECK:STDOUT: %return.param_patt: %pattern_type.cb1 = out_param_pattern %return.patt, call_param0 [concrete]
  154. // CHECK:STDOUT: } {
  155. // CHECK:STDOUT: %.loc49_12.1: %empty_tuple.type = tuple_literal ()
  156. // CHECK:STDOUT: %.loc49_12.2: type = converted %.loc49_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  157. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  158. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %J.decl.loc51: %J.type.8e2c84.1 = fn_decl @J.1 [concrete = constants.%J.3662e8.1] {
  161. // CHECK:STDOUT: %return.patt: %pattern_type.cb1 = return_slot_pattern [concrete]
  162. // CHECK:STDOUT: %return.param_patt: %pattern_type.cb1 = out_param_pattern %return.patt, call_param0 [concrete]
  163. // CHECK:STDOUT: } {
  164. // CHECK:STDOUT: %.loc51_12.1: %empty_tuple.type = tuple_literal ()
  165. // CHECK:STDOUT: %.loc51_12.2: type = converted %.loc51_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  166. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  167. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: %J.decl.loc59: %J.type.8e2c84.2 = fn_decl @J.2 [concrete = constants.%J.3662e8.2] {} {}
  170. // CHECK:STDOUT: %K.decl.loc61: %K.type.6cc1c5.1 = fn_decl @K.1 [concrete = constants.%K.460d95.1] {
  171. // CHECK:STDOUT: %return.patt: %pattern_type.cb1 = return_slot_pattern [concrete]
  172. // CHECK:STDOUT: %return.param_patt: %pattern_type.cb1 = out_param_pattern %return.patt, call_param0 [concrete]
  173. // CHECK:STDOUT: } {
  174. // CHECK:STDOUT: %.loc61_12.1: %empty_tuple.type = tuple_literal ()
  175. // CHECK:STDOUT: %.loc61_12.2: type = converted %.loc61_12.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  176. // CHECK:STDOUT: %return.param: ref %empty_tuple.type = out_param call_param0
  177. // CHECK:STDOUT: %return: ref %empty_tuple.type = return_slot %return.param
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT: %K.decl.loc69: %K.type.6cc1c5.2 = fn_decl @K.2 [concrete = constants.%K.460d95.2] {
  180. // CHECK:STDOUT: %return.patt: %pattern_type.a96 = return_slot_pattern [concrete]
  181. // CHECK:STDOUT: %return.param_patt: %pattern_type.a96 = out_param_pattern %return.patt, call_param0 [concrete]
  182. // CHECK:STDOUT: } {
  183. // CHECK:STDOUT: %.loc69_12.1: %empty_struct_type = struct_literal ()
  184. // CHECK:STDOUT: %.loc69_12.2: type = converted %.loc69_12.1, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  185. // CHECK:STDOUT: %return.param: ref %empty_struct_type = out_param call_param0
  186. // CHECK:STDOUT: %return: ref %empty_struct_type = return_slot %return.param
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn @F.1();
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: fn @F.2(%x.param: %empty_tuple.type) {
  193. // CHECK:STDOUT: !entry:
  194. // CHECK:STDOUT: return
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: fn @G.1(%x.param: %empty_tuple.type);
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: fn @G.2() {
  200. // CHECK:STDOUT: !entry:
  201. // CHECK:STDOUT: return
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: fn @H.1(%x.param: %empty_tuple.type);
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: fn @H.2(%x.param: <error>) {
  207. // CHECK:STDOUT: !entry:
  208. // CHECK:STDOUT: return
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: fn @I.1();
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: fn @I.2() -> %empty_tuple.type {
  214. // CHECK:STDOUT: !entry:
  215. // CHECK:STDOUT: %.loc49_24: %empty_tuple.type = tuple_literal ()
  216. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  217. // CHECK:STDOUT: %.loc49_25: %empty_tuple.type = converted %.loc49_24, %empty_tuple [concrete = constants.%empty_tuple]
  218. // CHECK:STDOUT: return %.loc49_25
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: fn @J.1() -> %empty_tuple.type;
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: fn @J.2() {
  224. // CHECK:STDOUT: !entry:
  225. // CHECK:STDOUT: return
  226. // CHECK:STDOUT: }
  227. // CHECK:STDOUT:
  228. // CHECK:STDOUT: fn @K.1() -> %empty_tuple.type;
  229. // CHECK:STDOUT:
  230. // CHECK:STDOUT: fn @K.2() -> %empty_struct_type {
  231. // CHECK:STDOUT: !entry:
  232. // CHECK:STDOUT: %.loc69_24: %empty_struct_type = struct_literal ()
  233. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  234. // CHECK:STDOUT: %.loc69_25: %empty_struct_type = converted %.loc69_24, %empty_struct [concrete = constants.%empty_struct]
  235. // CHECK:STDOUT: return %.loc69_25
  236. // CHECK:STDOUT: }
  237. // CHECK:STDOUT: