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.3e4: %i32 = bind_symbolic_name N, 0 [symbolic]
  39. // CHECK:STDOUT: %N.patt.52a: %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.71d: type = class_type @A, @A(%N.3e4) [symbolic]
  43. // CHECK:STDOUT: %A.elem.792: type = unbound_element_type %A.71d, %B [symbolic]
  44. // CHECK:STDOUT: %Convert.type.d18: type = fn_type @Convert.3, @impl.2(%int_32) [template]
  45. // CHECK:STDOUT: %Convert.079: %Convert.type.d18 = struct_value () [template]
  46. // CHECK:STDOUT: %Convert.bound.d9b: <bound method> = bound_method %N.3e4, %Convert.079 [symbolic]
  47. // CHECK:STDOUT: %Convert.specific_fn.ad3: <specific function> = specific_function %Convert.bound.d9b, @Convert.3(%int_32) [symbolic]
  48. // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn.ad3(%N.3e4) [symbolic]
  49. // CHECK:STDOUT: %iN.builtin.3ce: type = int_type signed, %int.convert_checked [symbolic]
  50. // CHECK:STDOUT: %require_complete.47c: <witness> = require_complete_type %iN.builtin.3ce [symbolic]
  51. // CHECK:STDOUT: %A.elem.674: type = unbound_element_type %A.71d, %iN.builtin.3ce [symbolic]
  52. // CHECK:STDOUT: %struct_type.base.n: type = struct_type {.base: %B, .n: %iN.builtin.3ce} [symbolic]
  53. // CHECK:STDOUT: %complete_type.8e3: <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.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  56. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  57. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  58. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  59. // CHECK:STDOUT: %Convert.bound.b41: <bound method> = bound_method %int_0.5c6, %Convert.925 [template]
  60. // CHECK:STDOUT: %Convert.specific_fn.c35: <specific function> = specific_function %Convert.bound.b41, @Convert.2(%int_32) [template]
  61. // CHECK:STDOUT: %int_0.f61: %i32 = int_value 0 [template]
  62. // CHECK:STDOUT: %A.b93: type = class_type @A, @A(%int_0.f61) [template]
  63. // CHECK:STDOUT: %ptr.ee1: type = ptr_type %A.b93 [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.fcc: type = unbound_element_type %A.b93, %B [template]
  68. // CHECK:STDOUT: %Convert.bound.64e: <bound method> = bound_method %int_0.f61, %Convert.079 [template]
  69. // CHECK:STDOUT: %Convert.specific_fn.f03: <specific function> = specific_function %Convert.bound.64e, @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.8ee
  75. // CHECK:STDOUT: .Int = %import_ref.187
  76. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  77. // CHECK:STDOUT: import Core//prelude
  78. // CHECK:STDOUT: import Core//prelude/...
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %import_ref.8ee: %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.8ee [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.52a)]
  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.52a)]
  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.3e4)]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  123. // CHECK:STDOUT: %a.patt: %ptr.ee1 = binding_pattern a
  124. // CHECK:STDOUT: %a.param_patt: %ptr.ee1 = value_param_pattern %a.patt, runtime_param0
  125. // CHECK:STDOUT: } {
  126. // CHECK:STDOUT: %a.param: %ptr.ee1 = value_param runtime_param0
  127. // CHECK:STDOUT: %.loc15_13: type = splice_block %ptr [template = constants.%ptr.ee1] {
  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.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  131. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound.b41]
  132. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.c35]
  133. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.f61]
  134. // CHECK:STDOUT: %.loc15_12.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_0.f61]
  135. // CHECK:STDOUT: %.loc15_12.2: %i32 = converted %int_0, %.loc15_12.1 [template = constants.%int_0.f61]
  136. // CHECK:STDOUT: %A: type = class_type @A, @A(constants.%int_0.f61) [template = constants.%A.b93]
  137. // CHECK:STDOUT: %ptr: type = ptr_type %A.b93 [template = constants.%ptr.ee1]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: %a: %ptr.ee1 = 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:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .Self = constants.%B
  148. // CHECK:STDOUT: complete_type_witness = %complete_type
  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.3e4)]
  153. // CHECK:STDOUT: %N.patt.loc6_9.2: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.52a)]
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: !definition:
  156. // CHECK:STDOUT: %A: type = class_type @A, @A(%N.loc6_9.2) [symbolic = %A (constants.%A.71d)]
  157. // CHECK:STDOUT: %A.elem.loc7: type = unbound_element_type @A.%A (%A.71d), %B [symbolic = %A.elem.loc7 (constants.%A.elem.792)]
  158. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %N.loc6_9.2, constants.%Convert.079 [symbolic = %Convert.bound (constants.%Convert.bound.d9b)]
  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.ad3)]
  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.3ce)]
  162. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type @A.%iN.builtin (%iN.builtin.3ce) [symbolic = %require_complete (constants.%require_complete.47c)]
  163. // CHECK:STDOUT: %A.elem.loc12: type = unbound_element_type @A.%A (%A.71d), @A.%iN.builtin (%iN.builtin.3ce) [symbolic = %A.elem.loc12 (constants.%A.elem.674)]
  164. // CHECK:STDOUT: %struct_type.base.n: type = struct_type {.base: %B, .n: @A.%iN.builtin (%iN.builtin.3ce)} [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.8e3)]
  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.792) = base_decl %B.ref, element0 [template]
  170. // CHECK:STDOUT: %.loc12: @A.%A.elem.loc12 (%A.elem.674) = 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.8e3)]
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: !members:
  174. // CHECK:STDOUT: .Self = constants.%A.71d
  175. // CHECK:STDOUT: .base = %.loc7
  176. // CHECK:STDOUT: .n = %.loc12
  177. // CHECK:STDOUT: extend %B.ref
  178. // CHECK:STDOUT: complete_type_witness = %complete_type.loc13_1.1
  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.ee1) {
  185. // CHECK:STDOUT: !entry:
  186. // CHECK:STDOUT: %a.ref: %ptr.ee1 = name_ref a, %a
  187. // CHECK:STDOUT: %.loc19_16.1: ref %A.b93 = 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.3e4) {
  196. // CHECK:STDOUT: %N.loc6_9.2 => constants.%N.3e4
  197. // CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%N.3e4
  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.f61) {
  203. // CHECK:STDOUT: %N.loc6_9.2 => constants.%int_0.f61
  204. // CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%int_0.f61
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: !definition:
  207. // CHECK:STDOUT: %A => constants.%A.b93
  208. // CHECK:STDOUT: %A.elem.loc7 => constants.%A.elem.fcc
  209. // CHECK:STDOUT: %Convert.bound => constants.%Convert.bound.64e
  210. // CHECK:STDOUT: %Convert.specific_fn => constants.%Convert.specific_fn.f03
  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: