fail_param_count.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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --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/call/fail_param_count.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/fail_param_count.carbon
  13. fn Run0() {}
  14. fn Run1(a: i32) {}
  15. fn Run2(a: i32, b: i32) {}
  16. fn Main() {
  17. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 0 arguments [CallArgCountMismatch]
  18. // CHECK:STDERR: Run0(1);
  19. // CHECK:STDERR: ^~~~~~~
  20. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-8]]:1: note: calling function declared here [InCallToEntity]
  21. // CHECK:STDERR: fn Run0() {}
  22. // CHECK:STDERR: ^~~~~~~~~~~
  23. // CHECK:STDERR:
  24. Run0(1);
  25. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 arguments passed to function expecting 0 arguments [CallArgCountMismatch]
  26. // CHECK:STDERR: Run0(0, 1);
  27. // CHECK:STDERR: ^~~~~~~~~~
  28. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-16]]:1: note: calling function declared here [InCallToEntity]
  29. // CHECK:STDERR: fn Run0() {}
  30. // CHECK:STDERR: ^~~~~~~~~~~
  31. // CHECK:STDERR:
  32. Run0(0, 1);
  33. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 0 arguments passed to function expecting 1 argument [CallArgCountMismatch]
  34. // CHECK:STDERR: Run1();
  35. // CHECK:STDERR: ^~~~~~
  36. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-24]]:1: note: calling function declared here [InCallToEntity]
  37. // CHECK:STDERR: fn Run1(a: i32) {}
  38. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  39. // CHECK:STDERR:
  40. Run1();
  41. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 arguments passed to function expecting 1 argument [CallArgCountMismatch]
  42. // CHECK:STDERR: Run1(0, 1);
  43. // CHECK:STDERR: ^~~~~~~~~~
  44. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-32]]:1: note: calling function declared here [InCallToEntity]
  45. // CHECK:STDERR: fn Run1(a: i32) {}
  46. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  47. // CHECK:STDERR:
  48. Run1(0, 1);
  49. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 0 arguments passed to function expecting 2 arguments [CallArgCountMismatch]
  50. // CHECK:STDERR: Run2();
  51. // CHECK:STDERR: ^~~~~~
  52. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-40]]:1: note: calling function declared here [InCallToEntity]
  53. // CHECK:STDERR: fn Run2(a: i32, b: i32) {}
  54. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  55. // CHECK:STDERR:
  56. Run2();
  57. // CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 2 arguments [CallArgCountMismatch]
  58. // CHECK:STDERR: Run2(0);
  59. // CHECK:STDERR: ^~~~~~~
  60. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-48]]:1: note: calling function declared here [InCallToEntity]
  61. // CHECK:STDERR: fn Run2(a: i32, b: i32) {}
  62. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  63. // CHECK:STDERR:
  64. Run2(0);
  65. }
  66. // CHECK:STDOUT: --- fail_param_count.carbon
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: constants {
  69. // CHECK:STDOUT: %Run0.type: type = fn_type @Run0 [concrete]
  70. // CHECK:STDOUT: %Run0: %Run0.type = struct_value () [concrete]
  71. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  72. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  73. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  74. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  75. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  76. // CHECK:STDOUT: %Run1.type: type = fn_type @Run1 [concrete]
  77. // CHECK:STDOUT: %Run1: %Run1.type = struct_value () [concrete]
  78. // CHECK:STDOUT: %Run2.type: type = fn_type @Run2 [concrete]
  79. // CHECK:STDOUT: %Run2: %Run2.type = struct_value () [concrete]
  80. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  81. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  82. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  83. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: imports {
  87. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  88. // CHECK:STDOUT: .Int = %Core.Int
  89. // CHECK:STDOUT: import Core//prelude
  90. // CHECK:STDOUT: import Core//prelude/...
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: file {
  96. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  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 [concrete = constants.%Run0] {} {}
  105. // CHECK:STDOUT: %Run1.decl: %Run1.type = fn_decl @Run1 [concrete = constants.%Run1] {
  106. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  107. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  108. // CHECK:STDOUT: } {
  109. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  110. // CHECK:STDOUT: %.loc15: type = splice_block %i32 [concrete = constants.%i32] {
  111. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  112. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %Run2.decl: %Run2.type = fn_decl @Run2 [concrete = constants.%Run2] {
  117. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  118. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  119. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = binding_pattern b [concrete]
  120. // CHECK:STDOUT: %b.param_patt: %pattern_type.7ce = value_param_pattern %b.patt, call_param1 [concrete]
  121. // CHECK:STDOUT: } {
  122. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  123. // CHECK:STDOUT: %.loc16_12: type = splice_block %i32.loc16_12 [concrete = constants.%i32] {
  124. // CHECK:STDOUT: %int_32.loc16_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  125. // CHECK:STDOUT: %i32.loc16_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  128. // CHECK:STDOUT: %b.param: %i32 = value_param call_param1
  129. // CHECK:STDOUT: %.loc16_20: type = splice_block %i32.loc16_20 [concrete = constants.%i32] {
  130. // CHECK:STDOUT: %int_32.loc16_20: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  131. // CHECK:STDOUT: %i32.loc16_20: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: fn @Run0() {
  139. // CHECK:STDOUT: !entry:
  140. // CHECK:STDOUT: return
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: fn @Run1(%a.param: %i32) {
  144. // CHECK:STDOUT: !entry:
  145. // CHECK:STDOUT: return
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: fn @Run2(%a.param: %i32, %b.param: %i32) {
  149. // CHECK:STDOUT: !entry:
  150. // CHECK:STDOUT: return
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: fn @Main() {
  154. // CHECK:STDOUT: !entry:
  155. // CHECK:STDOUT: %Run0.ref.loc26: %Run0.type = name_ref Run0, file.%Run0.decl [concrete = constants.%Run0]
  156. // CHECK:STDOUT: %int_1.loc26: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  157. // CHECK:STDOUT: %Run0.ref.loc34: %Run0.type = name_ref Run0, file.%Run0.decl [concrete = constants.%Run0]
  158. // CHECK:STDOUT: %int_0.loc34: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  159. // CHECK:STDOUT: %int_1.loc34: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  160. // CHECK:STDOUT: %Run1.ref.loc43: %Run1.type = name_ref Run1, file.%Run1.decl [concrete = constants.%Run1]
  161. // CHECK:STDOUT: %Run1.ref.loc51: %Run1.type = name_ref Run1, file.%Run1.decl [concrete = constants.%Run1]
  162. // CHECK:STDOUT: %int_0.loc51: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  163. // CHECK:STDOUT: %int_1.loc51: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  164. // CHECK:STDOUT: %Run2.ref.loc60: %Run2.type = name_ref Run2, file.%Run2.decl [concrete = constants.%Run2]
  165. // CHECK:STDOUT: %Run2.ref.loc68: %Run2.type = name_ref Run2, file.%Run2.decl [concrete = constants.%Run2]
  166. // CHECK:STDOUT: %int_0.loc68: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  167. // CHECK:STDOUT: return
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: