fail_param_count.carbon 8.6 KB

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