fail_param_count.carbon 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 passed to function expecting 0 arguments [CallArgCountMismatch]
  15. // CHECK:STDERR: Run0(1);
  16. // CHECK:STDERR: ^~~~~~~
  17. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-8]]:1: note: calling function declared here [InCallToEntity]
  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 arguments passed to function expecting 0 arguments [CallArgCountMismatch]
  23. // CHECK:STDERR: Run0(0, 1);
  24. // CHECK:STDERR: ^~~~~~~~~~
  25. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-16]]:1: note: calling function declared here [InCallToEntity]
  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 arguments passed to function expecting 1 argument [CallArgCountMismatch]
  31. // CHECK:STDERR: Run1();
  32. // CHECK:STDERR: ^~~~~~
  33. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-24]]:1: note: calling function declared here [InCallToEntity]
  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 arguments passed to function expecting 1 argument [CallArgCountMismatch]
  39. // CHECK:STDERR: Run1(0, 1);
  40. // CHECK:STDERR: ^~~~~~~~~~
  41. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-32]]:1: note: calling function declared here [InCallToEntity]
  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 arguments passed to function expecting 2 arguments [CallArgCountMismatch]
  47. // CHECK:STDERR: Run2();
  48. // CHECK:STDERR: ^~~~~~
  49. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-40]]:1: note: calling function declared here [InCallToEntity]
  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+7]]:3: error: 1 argument passed to function expecting 2 arguments [CallArgCountMismatch]
  55. // CHECK:STDERR: Run2(0);
  56. // CHECK:STDERR: ^~~~~~~
  57. // CHECK:STDERR: fail_param_count.carbon:[[@LINE-48]]:1: note: calling function declared here [InCallToEntity]
  58. // CHECK:STDERR: fn Run2(a: i32, b: i32) {}
  59. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  60. // CHECK:STDERR:
  61. Run2(0);
  62. }
  63. // CHECK:STDOUT: --- fail_param_count.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %Run0.type: type = fn_type @Run0 [concrete]
  67. // CHECK:STDOUT: %Run0: %Run0.type = struct_value () [concrete]
  68. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  69. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  70. // CHECK:STDOUT: %Run1.type: type = fn_type @Run1 [concrete]
  71. // CHECK:STDOUT: %Run1: %Run1.type = struct_value () [concrete]
  72. // CHECK:STDOUT: %Run2.type: type = fn_type @Run2 [concrete]
  73. // CHECK:STDOUT: %Run2: %Run2.type = struct_value () [concrete]
  74. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  75. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  76. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  77. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: imports {
  81. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  82. // CHECK:STDOUT: .Int = %Core.Int
  83. // CHECK:STDOUT: import Core//prelude
  84. // CHECK:STDOUT: import Core//prelude/...
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: file {
  89. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  90. // CHECK:STDOUT: .Core = imports.%Core
  91. // CHECK:STDOUT: .Run0 = %Run0.decl
  92. // CHECK:STDOUT: .Run1 = %Run1.decl
  93. // CHECK:STDOUT: .Run2 = %Run2.decl
  94. // CHECK:STDOUT: .Main = %Main.decl
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %Core.import = import Core
  97. // CHECK:STDOUT: %Run0.decl: %Run0.type = fn_decl @Run0 [concrete = constants.%Run0] {} {}
  98. // CHECK:STDOUT: %Run1.decl: %Run1.type = fn_decl @Run1 [concrete = constants.%Run1] {
  99. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  100. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, call_param0
  101. // CHECK:STDOUT: } {
  102. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  103. // CHECK:STDOUT: %.loc12: type = splice_block %i32 [concrete = constants.%i32] {
  104. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  105. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %Run2.decl: %Run2.type = fn_decl @Run2 [concrete = constants.%Run2] {
  110. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  111. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, call_param0
  112. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  113. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, call_param1
  114. // CHECK:STDOUT: } {
  115. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  116. // CHECK:STDOUT: %.loc13_12: type = splice_block %i32.loc13_12 [concrete = constants.%i32] {
  117. // CHECK:STDOUT: %int_32.loc13_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  118. // CHECK:STDOUT: %i32.loc13_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  121. // CHECK:STDOUT: %b.param: %i32 = value_param call_param1
  122. // CHECK:STDOUT: %.loc13_20: type = splice_block %i32.loc13_20 [concrete = constants.%i32] {
  123. // CHECK:STDOUT: %int_32.loc13_20: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  124. // CHECK:STDOUT: %i32.loc13_20: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @Run0() {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: return
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: fn @Run1(%a.param_patt: %i32) {
  137. // CHECK:STDOUT: !entry:
  138. // CHECK:STDOUT: return
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @Run2(%a.param_patt: %i32, %b.param_patt: %i32) {
  142. // CHECK:STDOUT: !entry:
  143. // CHECK:STDOUT: return
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: fn @Main() {
  147. // CHECK:STDOUT: !entry:
  148. // CHECK:STDOUT: %Run0.ref.loc23: %Run0.type = name_ref Run0, file.%Run0.decl [concrete = constants.%Run0]
  149. // CHECK:STDOUT: %int_1.loc23: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  150. // CHECK:STDOUT: %Run0.ref.loc31: %Run0.type = name_ref Run0, file.%Run0.decl [concrete = constants.%Run0]
  151. // CHECK:STDOUT: %int_0.loc31: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  152. // CHECK:STDOUT: %int_1.loc31: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  153. // CHECK:STDOUT: %Run1.ref.loc40: %Run1.type = name_ref Run1, file.%Run1.decl [concrete = constants.%Run1]
  154. // CHECK:STDOUT: %Run1.ref.loc48: %Run1.type = name_ref Run1, file.%Run1.decl [concrete = constants.%Run1]
  155. // CHECK:STDOUT: %int_0.loc48: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  156. // CHECK:STDOUT: %int_1.loc48: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  157. // CHECK:STDOUT: %Run2.ref.loc57: %Run2.type = name_ref Run2, file.%Run2.decl [concrete = constants.%Run2]
  158. // CHECK:STDOUT: %Run2.ref.loc65: %Run2.type = name_ref Run2, file.%Run2.decl [concrete = constants.%Run2]
  159. // CHECK:STDOUT: %int_0.loc65: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  160. // CHECK:STDOUT: return
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT: