call.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. // --- call.carbon
  7. library "call" api;
  8. class Class(T:! type, N:! i32) {}
  9. var a: Class(i32*, 5);
  10. // Requires an implicit conversion to type `type`.
  11. var b: Class((), 0);
  12. // --- fail_too_few.carbon
  13. library "too_few" api;
  14. class Class(T:! type, N:! i32) {}
  15. // CHECK:STDERR: fail_too_few.carbon:[[@LINE+7]]:8: ERROR: 1 argument(s) passed to function expecting 2 argument(s).
  16. // CHECK:STDERR: var a: Class(i32*);
  17. // CHECK:STDERR: ^~~~~~
  18. // CHECK:STDERR: fail_too_few.carbon:[[@LINE-5]]:1: Calling function declared here.
  19. // CHECK:STDERR: class Class(T:! type, N:! i32) {}
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. var a: Class(i32*);
  23. // --- fail_too_many.carbon
  24. library "too_many" api;
  25. class Class(T:! type, N:! i32) {}
  26. // CHECK:STDERR: fail_too_many.carbon:[[@LINE+7]]:8: ERROR: 3 argument(s) passed to function expecting 2 argument(s).
  27. // CHECK:STDERR: var a: Class(i32*, 1, 2);
  28. // CHECK:STDERR: ^~~~~~
  29. // CHECK:STDERR: fail_too_many.carbon:[[@LINE-5]]:1: Calling function declared here.
  30. // CHECK:STDERR: class Class(T:! type, N:! i32) {}
  31. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. // CHECK:STDERR:
  33. var a: Class(i32*, 1, 2);
  34. // --- fail_no_conversion.carbon
  35. library "no_conversion" api;
  36. class Class(T:! type, N:! i32) {}
  37. // CHECK:STDERR: fail_no_conversion.carbon:[[@LINE+6]]:8: ERROR: Cannot implicitly convert from `i32` to `type`.
  38. // CHECK:STDERR: var a: Class(5, i32*);
  39. // CHECK:STDERR: ^~~~~~
  40. // CHECK:STDERR: fail_no_conversion.carbon:[[@LINE-5]]:1: Initializing parameter 1 of function declared here.
  41. // CHECK:STDERR: class Class(T:! type, N:! i32) {}
  42. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. var a: Class(5, i32*);
  44. // CHECK:STDOUT: --- call.carbon
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: constants {
  47. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  48. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N 1 [symbolic]
  49. // CHECK:STDOUT: %Class.1: type = generic_class_type @Class [template]
  50. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  51. // CHECK:STDOUT: %struct: Class = struct_value () [template]
  52. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  53. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  54. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  55. // CHECK:STDOUT: %.4: i32 = int_literal 5 [template]
  56. // CHECK:STDOUT: %Class.3: type = class_type @Class, (file.%.loc6_17, file.%.loc6_20) [template]
  57. // CHECK:STDOUT: %.5: type = ptr_type {} [template]
  58. // CHECK:STDOUT: %.6: i32 = int_literal 0 [template]
  59. // CHECK:STDOUT: %Class.4: type = class_type @Class, (file.%.loc9_13, file.%.loc9_18) [template]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = %Core
  65. // CHECK:STDOUT: .Class = %Class.decl
  66. // CHECK:STDOUT: .a = %a
  67. // CHECK:STDOUT: .b = %b
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  70. // CHECK:STDOUT: %Class.decl: Class = class_decl @Class [template = constants.%struct] {
  71. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  72. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  73. // CHECK:STDOUT: %N.loc4_23.1: i32 = param N
  74. // CHECK:STDOUT: %N.loc4_23.2: i32 = bind_symbolic_name N 1, %N.loc4_23.1 [symbolic = constants.%N]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Class.ref.loc6: Class = name_ref Class, %Class.decl [template = constants.%struct]
  77. // CHECK:STDOUT: %.loc6_17: type = ptr_type i32 [template = constants.%.3]
  78. // CHECK:STDOUT: %.loc6_20: i32 = int_literal 5 [template = constants.%.4]
  79. // CHECK:STDOUT: %Class.loc6: type = class_type @Class, (%.loc6_17, %.loc6_20) [template = constants.%Class.3]
  80. // CHECK:STDOUT: %a.var: ref Class = var a
  81. // CHECK:STDOUT: %a: ref Class = bind_name a, %a.var
  82. // CHECK:STDOUT: %Class.ref.loc9: Class = name_ref Class, %Class.decl [template = constants.%struct]
  83. // CHECK:STDOUT: %.loc9_15: () = tuple_literal ()
  84. // CHECK:STDOUT: %.loc9_18: i32 = int_literal 0 [template = constants.%.6]
  85. // CHECK:STDOUT: %.loc9_13: type = converted %.loc9_15, constants.%.1 [template = constants.%.1]
  86. // CHECK:STDOUT: %Class.loc9: type = class_type @Class, (%.loc9_13, %.loc9_18) [template = constants.%Class.4]
  87. // CHECK:STDOUT: %b.var: ref Class = var b
  88. // CHECK:STDOUT: %b: ref Class = bind_name b, %b.var
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: class @Class {
  92. // CHECK:STDOUT: !members:
  93. // CHECK:STDOUT: .Self = constants.%Class.2
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: --- fail_too_few.carbon
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: constants {
  99. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  100. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N 1 [symbolic]
  101. // CHECK:STDOUT: %Class.1: type = generic_class_type @Class [template]
  102. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  103. // CHECK:STDOUT: %struct: Class = struct_value () [template]
  104. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  105. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  106. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  107. // CHECK:STDOUT: %.4: type = ptr_type {} [template]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: file {
  111. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  112. // CHECK:STDOUT: .Core = %Core
  113. // CHECK:STDOUT: .Class = %Class.decl
  114. // CHECK:STDOUT: .a = %a
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  117. // CHECK:STDOUT: %Class.decl: Class = class_decl @Class [template = constants.%struct] {
  118. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  119. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  120. // CHECK:STDOUT: %N.loc4_23.1: i32 = param N
  121. // CHECK:STDOUT: %N.loc4_23.2: i32 = bind_symbolic_name N 1, %N.loc4_23.1 [symbolic = constants.%N]
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %Class.ref: Class = name_ref Class, %Class.decl [template = constants.%struct]
  124. // CHECK:STDOUT: %.loc13: type = ptr_type i32 [template = constants.%.3]
  125. // CHECK:STDOUT: %Class: type = class_type @Class [template = constants.%Class.2]
  126. // CHECK:STDOUT: %a.var: ref Class = var a
  127. // CHECK:STDOUT: %a: ref Class = bind_name a, %a.var
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: class @Class {
  131. // CHECK:STDOUT: !members:
  132. // CHECK:STDOUT: .Self = constants.%Class.2
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: --- fail_too_many.carbon
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: constants {
  138. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  139. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N 1 [symbolic]
  140. // CHECK:STDOUT: %Class.1: type = generic_class_type @Class [template]
  141. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  142. // CHECK:STDOUT: %struct: Class = struct_value () [template]
  143. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  144. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  145. // CHECK:STDOUT: %.3: type = ptr_type i32 [template]
  146. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  147. // CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
  148. // CHECK:STDOUT: %.6: type = ptr_type {} [template]
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: file {
  152. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  153. // CHECK:STDOUT: .Core = %Core
  154. // CHECK:STDOUT: .Class = %Class.decl
  155. // CHECK:STDOUT: .a = %a
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  158. // CHECK:STDOUT: %Class.decl: Class = class_decl @Class [template = constants.%struct] {
  159. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  160. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  161. // CHECK:STDOUT: %N.loc4_23.1: i32 = param N
  162. // CHECK:STDOUT: %N.loc4_23.2: i32 = bind_symbolic_name N 1, %N.loc4_23.1 [symbolic = constants.%N]
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT: %Class.ref: Class = name_ref Class, %Class.decl [template = constants.%struct]
  165. // CHECK:STDOUT: %.loc13_17: type = ptr_type i32 [template = constants.%.3]
  166. // CHECK:STDOUT: %.loc13_20: i32 = int_literal 1 [template = constants.%.4]
  167. // CHECK:STDOUT: %.loc13_23: i32 = int_literal 2 [template = constants.%.5]
  168. // CHECK:STDOUT: %Class: type = class_type @Class [template = constants.%Class.2]
  169. // CHECK:STDOUT: %a.var: ref Class = var a
  170. // CHECK:STDOUT: %a: ref Class = bind_name a, %a.var
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: class @Class {
  174. // CHECK:STDOUT: !members:
  175. // CHECK:STDOUT: .Self = constants.%Class.2
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: --- fail_no_conversion.carbon
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: constants {
  181. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  182. // CHECK:STDOUT: %N: i32 = bind_symbolic_name N 1 [symbolic]
  183. // CHECK:STDOUT: %Class.1: type = generic_class_type @Class [template]
  184. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  185. // CHECK:STDOUT: %struct: Class = struct_value () [template]
  186. // CHECK:STDOUT: %Class.2: type = class_type @Class [template]
  187. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  188. // CHECK:STDOUT: %.3: i32 = int_literal 5 [template]
  189. // CHECK:STDOUT: %.4: type = ptr_type i32 [template]
  190. // CHECK:STDOUT: %.5: type = ptr_type {} [template]
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: file {
  194. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  195. // CHECK:STDOUT: .Core = %Core
  196. // CHECK:STDOUT: .Class = %Class.decl
  197. // CHECK:STDOUT: .a = %a
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  200. // CHECK:STDOUT: %Class.decl: Class = class_decl @Class [template = constants.%struct] {
  201. // CHECK:STDOUT: %T.loc4_13.1: type = param T
  202. // CHECK:STDOUT: %T.loc4_13.2: type = bind_symbolic_name T 0, %T.loc4_13.1 [symbolic = constants.%T]
  203. // CHECK:STDOUT: %N.loc4_23.1: i32 = param N
  204. // CHECK:STDOUT: %N.loc4_23.2: i32 = bind_symbolic_name N 1, %N.loc4_23.1 [symbolic = constants.%N]
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT: %Class.ref: Class = name_ref Class, %Class.decl [template = constants.%struct]
  207. // CHECK:STDOUT: %.loc12_14: i32 = int_literal 5 [template = constants.%.3]
  208. // CHECK:STDOUT: %.loc12_20: type = ptr_type i32 [template = constants.%.4]
  209. // CHECK:STDOUT: %Class: type = class_type @Class [template = constants.%Class.2]
  210. // CHECK:STDOUT: %a.var: ref Class = var a
  211. // CHECK:STDOUT: %a: ref Class = bind_name a, %a.var
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: class @Class {
  215. // CHECK:STDOUT: !members:
  216. // CHECK:STDOUT: .Self = constants.%Class.2
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT: