complete_in_conversion.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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/class/generic/complete_in_conversion.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/complete_in_conversion.carbon
  10. // --- fail_derived_to_base.carbon
  11. fn Int(N: Core.IntLiteral()) -> type = "int.make_type_signed";
  12. base class B {}
  13. class A(N:! i32) {
  14. extend base: B;
  15. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+3]]:10: error: integer type width of 0 is not positive [IntWidthNotPositive]
  16. // CHECK:STDERR: var n: Int(N);
  17. // CHECK:STDERR: ^~~~~~
  18. var n: Int(N);
  19. }
  20. fn F(a: A(0)*) {
  21. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+3]]:3: note: in `A(0)` used here [ResolvingSpecificHere]
  22. // CHECK:STDERR: let b: B* = a;
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~
  24. let b: B* = a;
  25. }
  26. // CHECK:STDOUT: --- fail_derived_to_base.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %IntLiteral.type: type = fn_type @IntLiteral [template]
  30. // CHECK:STDOUT: %IntLiteral: %IntLiteral.type = struct_value () [template]
  31. // CHECK:STDOUT: %Int.type.913: type = fn_type @Int.1 [template]
  32. // CHECK:STDOUT: %Int.779: %Int.type.913 = struct_value () [template]
  33. // CHECK:STDOUT: %B: type = class_type @B [template]
  34. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  35. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  36. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  37. // CHECK:STDOUT: %i32: type = class_type @Int.2, @Int.2(%int_32) [template]
  38. // CHECK:STDOUT: %N.51e: %i32 = bind_symbolic_name N, 0 [symbolic]
  39. // CHECK:STDOUT: %N.patt.8e2: %i32 = symbolic_binding_pattern N, 0 [symbolic]
  40. // CHECK:STDOUT: %A.type: type = generic_class_type @A [template]
  41. // CHECK:STDOUT: %A.generic: %A.type = struct_value () [template]
  42. // CHECK:STDOUT: %A.dd3: type = class_type @A, @A(%N.51e) [symbolic]
  43. // CHECK:STDOUT: %A.elem.500: type = unbound_element_type %A.dd3, %B [symbolic]
  44. // CHECK:STDOUT: %Convert.type.4ad: type = fn_type @Convert.3, @impl.2(%int_32) [template]
  45. // CHECK:STDOUT: %Convert.960: %Convert.type.4ad = struct_value () [template]
  46. // CHECK:STDOUT: %Convert.bound.588: <bound method> = bound_method %N.51e, %Convert.960 [symbolic]
  47. // CHECK:STDOUT: %Convert.specific_fn.18b: <specific function> = specific_function %Convert.bound.588, @Convert.3(%int_32) [symbolic]
  48. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn.18b(%N.51e) [symbolic]
  49. // CHECK:STDOUT: %iN.builtin.c5d: type = int_type signed, %int.convert_checked [symbolic]
  50. // CHECK:STDOUT: %require_complete.be5: <witness> = require_complete_type %iN.builtin.c5d [symbolic]
  51. // CHECK:STDOUT: %A.elem.d60: type = unbound_element_type %A.dd3, %iN.builtin.c5d [symbolic]
  52. // CHECK:STDOUT: %struct_type.base.n: type = struct_type {.base: %B, .n: %iN.builtin.c5d} [symbolic]
  53. // CHECK:STDOUT: %complete_type.547: <witness> = complete_type_witness %struct_type.base.n [symbolic]
  54. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
  55. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  56. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%import_ref.a5b), @impl.1(%int_32) [template]
  57. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  58. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  59. // CHECK:STDOUT: %Convert.bound.d04: <bound method> = bound_method %int_0.5c6, %Convert.956 [template]
  60. // CHECK:STDOUT: %Convert.specific_fn.d62: <specific function> = specific_function %Convert.bound.d04, @Convert.2(%int_32) [template]
  61. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [template]
  62. // CHECK:STDOUT: %A.6fc: type = class_type @A, @A(%int_0.6a9) [template]
  63. // CHECK:STDOUT: %ptr.b65: type = ptr_type %A.6fc [template]
  64. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  65. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  66. // CHECK:STDOUT: %ptr.e79: type = ptr_type %B [template]
  67. // CHECK:STDOUT: %A.elem.d81: type = unbound_element_type %A.6fc, %B [template]
  68. // CHECK:STDOUT: %Convert.bound.0fd: <bound method> = bound_method %int_0.6a9, %Convert.960 [template]
  69. // CHECK:STDOUT: %Convert.specific_fn.f3f: <specific function> = specific_function %Convert.bound.0fd, @Convert.3(%int_32) [template]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: imports {
  73. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  74. // CHECK:STDOUT: .IntLiteral = %import_ref.72f0
  75. // CHECK:STDOUT: .Int = %import_ref.485
  76. // CHECK:STDOUT: .ImplicitAs = %import_ref.d44
  77. // CHECK:STDOUT: import Core//prelude
  78. // CHECK:STDOUT: import Core//prelude/...
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %import_ref.72f0: %IntLiteral.type = import_ref Core//prelude/types/int_literal, IntLiteral, loaded [template = constants.%IntLiteral]
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: file {
  84. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  85. // CHECK:STDOUT: .Core = imports.%Core
  86. // CHECK:STDOUT: .Int = %Int.decl
  87. // CHECK:STDOUT: .B = %B.decl
  88. // CHECK:STDOUT: .A = %A.decl
  89. // CHECK:STDOUT: .F = %F.decl
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %Core.import = import Core
  92. // CHECK:STDOUT: %Int.decl: %Int.type.913 = fn_decl @Int.1 [template = constants.%Int.779] {
  93. // CHECK:STDOUT: %N.patt: Core.IntLiteral = binding_pattern N
  94. // CHECK:STDOUT: %N.param_patt: Core.IntLiteral = value_param_pattern %N.patt, runtime_param0
  95. // CHECK:STDOUT: %return.patt: type = return_slot_pattern
  96. // CHECK:STDOUT: %return.param_patt: type = out_param_pattern %return.patt, runtime_param1
  97. // CHECK:STDOUT: } {
  98. // CHECK:STDOUT: %N.param: Core.IntLiteral = value_param runtime_param0
  99. // CHECK:STDOUT: %.loc2_27.1: type = splice_block %.loc2_27.3 [template = Core.IntLiteral] {
  100. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  101. // CHECK:STDOUT: %IntLiteral.ref: %IntLiteral.type = name_ref IntLiteral, imports.%import_ref.72f0 [template = constants.%IntLiteral]
  102. // CHECK:STDOUT: %int_literal.make_type: init type = call %IntLiteral.ref() [template = Core.IntLiteral]
  103. // CHECK:STDOUT: %.loc2_27.2: type = value_of_initializer %int_literal.make_type [template = Core.IntLiteral]
  104. // CHECK:STDOUT: %.loc2_27.3: type = converted %int_literal.make_type, %.loc2_27.2 [template = Core.IntLiteral]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %N: Core.IntLiteral = bind_name N, %N.param
  107. // CHECK:STDOUT: %return.param: ref type = out_param runtime_param1
  108. // CHECK:STDOUT: %return: ref type = return_slot %return.param
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  111. // CHECK:STDOUT: %A.decl: %A.type = class_decl @A [template = constants.%A.generic] {
  112. // CHECK:STDOUT: %N.patt.loc6_9.1: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.8e2)]
  113. // CHECK:STDOUT: %N.param_patt: %i32 = value_param_pattern %N.patt.loc6_9.1, runtime_param<invalid> [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.8e2)]
  114. // CHECK:STDOUT: } {
  115. // CHECK:STDOUT: %N.param: %i32 = value_param runtime_param<invalid>
  116. // CHECK:STDOUT: %.loc6: type = splice_block %i32 [template = constants.%i32] {
  117. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  118. // CHECK:STDOUT: %i32: type = class_type @Int.2, @Int.2(constants.%int_32) [template = constants.%i32]
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: %N.loc6_9.1: %i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc6_9.2 (constants.%N.51e)]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  123. // CHECK:STDOUT: %a.patt: %ptr.b65 = binding_pattern a
  124. // CHECK:STDOUT: %a.param_patt: %ptr.b65 = value_param_pattern %a.patt, runtime_param0
  125. // CHECK:STDOUT: } {
  126. // CHECK:STDOUT: %a.param: %ptr.b65 = value_param runtime_param0
  127. // CHECK:STDOUT: %.loc15_13: type = splice_block %ptr [template = constants.%ptr.b65] {
  128. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A.generic]
  129. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
  130. // CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  131. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound.d04]
  132. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.d62]
  133. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.6a9]
  134. // CHECK:STDOUT: %.loc15_12.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_0.6a9]
  135. // CHECK:STDOUT: %.loc15_12.2: %i32 = converted %int_0, %.loc15_12.1 [template = constants.%int_0.6a9]
  136. // CHECK:STDOUT: %A: type = class_type @A, @A(constants.%int_0.6a9) [template = constants.%A.6fc]
  137. // CHECK:STDOUT: %ptr: type = ptr_type %A.6fc [template = constants.%ptr.b65]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: %a: %ptr.b65 = bind_name a, %a.param
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: class @B {
  144. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  145. // CHECK:STDOUT: complete_type_witness = %complete_type
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !members:
  148. // CHECK:STDOUT: .Self = constants.%B
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: generic class @A(%N.loc6_9.1: %i32) {
  152. // CHECK:STDOUT: %N.loc6_9.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc6_9.2 (constants.%N.51e)]
  153. // CHECK:STDOUT: %N.patt.loc6_9.2: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.8e2)]
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: !definition:
  156. // CHECK:STDOUT: %A: type = class_type @A, @A(%N.loc6_9.2) [symbolic = %A (constants.%A.dd3)]
  157. // CHECK:STDOUT: %A.elem.loc7: type = unbound_element_type @A.%A (%A.dd3), %B [symbolic = %A.elem.loc7 (constants.%A.elem.500)]
  158. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %N.loc6_9.2, constants.%Convert.960 [symbolic = %Convert.bound (constants.%Convert.bound.588)]
  159. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.3(constants.%int_32) [symbolic = %Convert.specific_fn (constants.%Convert.specific_fn.18b)]
  160. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn(%N.loc6_9.2) [symbolic = %int.convert_checked (constants.%int.convert_checked)]
  161. // CHECK:STDOUT: %iN.builtin: type = int_type signed, %int.convert_checked [symbolic = %iN.builtin (constants.%iN.builtin.c5d)]
  162. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @A.%iN.builtin (%iN.builtin.c5d) [symbolic = %require_complete (constants.%require_complete.be5)]
  163. // CHECK:STDOUT: %A.elem.loc12: type = unbound_element_type @A.%A (%A.dd3), @A.%iN.builtin (%iN.builtin.c5d) [symbolic = %A.elem.loc12 (constants.%A.elem.d60)]
  164. // CHECK:STDOUT: %struct_type.base.n: type = struct_type {.base: %B, .n: @A.%iN.builtin (%iN.builtin.c5d)} [symbolic = %struct_type.base.n (constants.%struct_type.base.n)]
  165. // CHECK:STDOUT: %complete_type.loc13_1.2: <witness> = complete_type_witness @A.%struct_type.base.n (%struct_type.base.n) [symbolic = %complete_type.loc13_1.2 (constants.%complete_type.547)]
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: class {
  168. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  169. // CHECK:STDOUT: %.loc7: @A.%A.elem.loc7 (%A.elem.500) = base_decl %B.ref, element0 [template]
  170. // CHECK:STDOUT: %.loc12: @A.%A.elem.loc12 (%A.elem.d60) = field_decl n, element1 [template]
  171. // CHECK:STDOUT: %complete_type.loc13_1.1: <witness> = complete_type_witness %struct_type.base.n [symbolic = %complete_type.loc13_1.2 (constants.%complete_type.547)]
  172. // CHECK:STDOUT: complete_type_witness = %complete_type.loc13_1.1
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: !members:
  175. // CHECK:STDOUT: .Self = constants.%A.dd3
  176. // CHECK:STDOUT: .base = %.loc7
  177. // CHECK:STDOUT: .n = %.loc12
  178. // CHECK:STDOUT: extend %B.ref
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: fn @Int.1(%N.param_patt: Core.IntLiteral) -> type = "int.make_type_signed";
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: fn @F(%a.param_patt: %ptr.b65) {
  185. // CHECK:STDOUT: !entry:
  186. // CHECK:STDOUT: %a.ref: %ptr.b65 = name_ref a, %a
  187. // CHECK:STDOUT: %.loc19_16.1: ref %A.6fc = deref %a.ref
  188. // CHECK:STDOUT: %.loc19_16.2: ref %B = class_element_access %.loc19_16.1, element0
  189. // CHECK:STDOUT: %addr: %ptr.e79 = addr_of %.loc19_16.2
  190. // CHECK:STDOUT: %.loc19_16.3: %ptr.e79 = converted %a.ref, %addr
  191. // CHECK:STDOUT: %b: %ptr.e79 = bind_name b, %.loc19_16.3
  192. // CHECK:STDOUT: return
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: specific @A(constants.%N.51e) {
  196. // CHECK:STDOUT: %N.loc6_9.2 => constants.%N.51e
  197. // CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%N.51e
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: specific @A(%N.loc6_9.2) {}
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: specific @A(constants.%int_0.6a9) {
  203. // CHECK:STDOUT: %N.loc6_9.2 => constants.%int_0.6a9
  204. // CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%int_0.6a9
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: !definition:
  207. // CHECK:STDOUT: %A => constants.%A.6fc
  208. // CHECK:STDOUT: %A.elem.loc7 => constants.%A.elem.d81
  209. // CHECK:STDOUT: %Convert.bound => constants.%Convert.bound.0fd
  210. // CHECK:STDOUT: %Convert.specific_fn => constants.%Convert.specific_fn.f3f
  211. // CHECK:STDOUT: %int.convert_checked => constants.%int_0.5c6
  212. // CHECK:STDOUT: %iN.builtin => <error>
  213. // CHECK:STDOUT: %require_complete => <error>
  214. // CHECK:STDOUT: %A.elem.loc12 => <error>
  215. // CHECK:STDOUT: %struct_type.base.n => <error>
  216. // CHECK:STDOUT: %complete_type.loc13_1.2 => <error>
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT: