fail_param_count.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/function/call/fail_param_count.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/fail_param_count.carbon
  10. fn Run0() {}
  11. fn Run1(a: i32) {}
  12. fn Run2(a: i32, b: i32) {}
  13. fn Main() {
  14. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 1 argument(s) passed to function expecting 0 argument(s).
  15. // CHECK:STDERR: Run0(1);
  16. // CHECK:STDERR: ^~~~~
  17. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-8]]:1: note: calling function declared here
  18. // CHECK:STDERR: fn Run0() {}
  19. // CHECK:STDERR: ^~~~~~~~~~~
  20. // CHECK:STDERR:
  21. Run0(1);
  22. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 argument(s) passed to function expecting 0 argument(s).
  23. // CHECK:STDERR: Run0(0, 1);
  24. // CHECK:STDERR: ^~~~~
  25. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-16]]:1: note: calling function declared here
  26. // CHECK:STDERR: fn Run0() {}
  27. // CHECK:STDERR: ^~~~~~~~~~~
  28. // CHECK:STDERR:
  29. Run0(0, 1);
  30. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 0 argument(s) passed to function expecting 1 argument(s).
  31. // CHECK:STDERR: Run1();
  32. // CHECK:STDERR: ^~~~~
  33. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-24]]:1: note: calling function declared here
  34. // CHECK:STDERR: fn Run1(a: i32) {}
  35. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  36. // CHECK:STDERR:
  37. Run1();
  38. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 argument(s) passed to function expecting 1 argument(s).
  39. // CHECK:STDERR: Run1(0, 1);
  40. // CHECK:STDERR: ^~~~~
  41. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-32]]:1: note: calling function declared here
  42. // CHECK:STDERR: fn Run1(a: i32) {}
  43. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  44. // CHECK:STDERR:
  45. Run1(0, 1);
  46. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 0 argument(s) passed to function expecting 2 argument(s).
  47. // CHECK:STDERR: Run2();
  48. // CHECK:STDERR: ^~~~~
  49. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-40]]:1: note: calling function declared here
  50. // CHECK:STDERR: fn Run2(a: i32, b: i32) {}
  51. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  52. // CHECK:STDERR:
  53. Run2();
  54. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+6]]:3: error: 1 argument(s) passed to function expecting 2 argument(s).
  55. // CHECK:STDERR: Run2(0);
  56. // CHECK:STDERR: ^~~~~
  57. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-48]]:1: note: calling function declared here
  58. // CHECK:STDERR: fn Run2(a: i32, b: i32) {}
  59. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  60. Run2(0);
  61. }
  62. // CHECK:STDOUT: --- fail_param_count.carbon
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: constants {
  65. // CHECK:STDOUT: %Run0.type: type = fn_type @Run0 [template]
  66. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  67. // CHECK:STDOUT: %Run0: %Run0.type = struct_value () [template]
  68. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  69. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  70. // CHECK:STDOUT: %Run1.type: type = fn_type @Run1 [template]
  71. // CHECK:STDOUT: %Run1: %Run1.type = struct_value () [template]
  72. // CHECK:STDOUT: %Run2.type: type = fn_type @Run2 [template]
  73. // CHECK:STDOUT: %Run2: %Run2.type = struct_value () [template]
  74. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  75. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  76. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  77. // CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: imports {
  81. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  82. // CHECK:STDOUT: .Int32 = %import_ref
  83. // CHECK:STDOUT: import Core//prelude
  84. // CHECK:STDOUT: import Core//prelude/operators
  85. // CHECK:STDOUT: import Core//prelude/types
  86. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  87. // CHECK:STDOUT: import Core//prelude/operators/as
  88. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  89. // CHECK:STDOUT: import Core//prelude/operators/comparison
  90. // CHECK:STDOUT: import Core//prelude/types/bool
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: file {
  96. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  97. // CHECK:STDOUT: .Core = imports.%Core
  98. // CHECK:STDOUT: .Run0 = %Run0.decl
  99. // CHECK:STDOUT: .Run1 = %Run1.decl
  100. // CHECK:STDOUT: .Run2 = %Run2.decl
  101. // CHECK:STDOUT: .Main = %Main.decl
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %Core.import = import Core
  104. // CHECK:STDOUT: %Run0.decl: %Run0.type = fn_decl @Run0 [template = constants.%Run0] {} {}
  105. // CHECK:STDOUT: %Run1.decl: %Run1.type = fn_decl @Run1 [template = constants.%Run1] {
  106. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  107. // CHECK:STDOUT: } {
  108. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  109. // CHECK:STDOUT: %.loc12_12.1: type = value_of_initializer %int.make_type_32 [template = i32]
  110. // CHECK:STDOUT: %.loc12_12.2: type = converted %int.make_type_32, %.loc12_12.1 [template = i32]
  111. // CHECK:STDOUT: %a.param: i32 = param a, runtime_param0
  112. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %Run2.decl: %Run2.type = fn_decl @Run2 [template = constants.%Run2] {
  115. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  116. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  117. // CHECK:STDOUT: } {
  118. // CHECK:STDOUT: %int.make_type_32.loc13_12: init type = call constants.%Int32() [template = i32]
  119. // CHECK:STDOUT: %.loc13_12.1: type = value_of_initializer %int.make_type_32.loc13_12 [template = i32]
  120. // CHECK:STDOUT: %.loc13_12.2: type = converted %int.make_type_32.loc13_12, %.loc13_12.1 [template = i32]
  121. // CHECK:STDOUT: %a.param: i32 = param a, runtime_param0
  122. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  123. // CHECK:STDOUT: %int.make_type_32.loc13_20: init type = call constants.%Int32() [template = i32]
  124. // CHECK:STDOUT: %.loc13_20.1: type = value_of_initializer %int.make_type_32.loc13_20 [template = i32]
  125. // CHECK:STDOUT: %.loc13_20.2: type = converted %int.make_type_32.loc13_20, %.loc13_20.1 [template = i32]
  126. // CHECK:STDOUT: %b.param: i32 = param b, runtime_param1
  127. // CHECK:STDOUT: %b: i32 = bind_name b, %b.param
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: fn @Run0() {
  133. // CHECK:STDOUT: !entry:
  134. // CHECK:STDOUT: return
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: fn @Run1(%a: i32) {
  140. // CHECK:STDOUT: !entry:
  141. // CHECK:STDOUT: return
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: fn @Run2(%a: i32, %b: i32) {
  145. // CHECK:STDOUT: !entry:
  146. // CHECK:STDOUT: return
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: fn @Main() {
  150. // CHECK:STDOUT: !entry:
  151. // CHECK:STDOUT: %Run0.ref.loc23: %Run0.type = name_ref Run0, file.%Run0.decl [template = constants.%Run0]
  152. // CHECK:STDOUT: %.loc23: i32 = int_literal 1 [template = constants.%.2]
  153. // CHECK:STDOUT: %Run0.ref.loc31: %Run0.type = name_ref Run0, file.%Run0.decl [template = constants.%Run0]
  154. // CHECK:STDOUT: %.loc31_8: i32 = int_literal 0 [template = constants.%.3]
  155. // CHECK:STDOUT: %.loc31_11: i32 = int_literal 1 [template = constants.%.2]
  156. // CHECK:STDOUT: %Run1.ref.loc40: %Run1.type = name_ref Run1, file.%Run1.decl [template = constants.%Run1]
  157. // CHECK:STDOUT: %Run1.ref.loc48: %Run1.type = name_ref Run1, file.%Run1.decl [template = constants.%Run1]
  158. // CHECK:STDOUT: %.loc48_8: i32 = int_literal 0 [template = constants.%.3]
  159. // CHECK:STDOUT: %.loc48_11: i32 = int_literal 1 [template = constants.%.2]
  160. // CHECK:STDOUT: %Run2.ref.loc57: %Run2.type = name_ref Run2, file.%Run2.decl [template = constants.%Run2]
  161. // CHECK:STDOUT: %Run2.ref.loc64: %Run2.type = name_ref Run2, file.%Run2.decl [template = constants.%Run2]
  162. // CHECK:STDOUT: %.loc64: i32 = int_literal 0 [template = constants.%.3]
  163. // CHECK:STDOUT: return
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: