fail_adapt_with_subobjects.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/fail_adapt_with_subobjects.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_adapt_with_subobjects.carbon
  10. // --- fail_adapt_with_base.carbon
  11. library "[[@TEST_NAME]]";
  12. base class Base {}
  13. class AdaptWithBase {
  14. // CHECK:STDERR: fail_adapt_with_base.carbon:[[@LINE+3]]:3: error: adapter with base class [AdaptWithBase]
  15. // CHECK:STDERR: adapt i32;
  16. // CHECK:STDERR: ^~~~~~~~~~
  17. adapt i32;
  18. // CHECK:STDERR: fail_adapt_with_base.carbon:[[@LINE+4]]:3: note: `base` declaration is here [AdaptWithBaseHere]
  19. // CHECK:STDERR: extend base: Base;
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. extend base: Base;
  23. }
  24. // --- fail_adapt_with_fields.carbon
  25. library "[[@TEST_NAME]]";
  26. class AdaptWithField {
  27. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+3]]:3: error: adapter with fields [AdaptWithFields]
  28. // CHECK:STDERR: adapt i32;
  29. // CHECK:STDERR: ^~~~~~~~~~
  30. adapt i32;
  31. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+4]]:7: note: first field declaration is here [AdaptWithFieldHere]
  32. // CHECK:STDERR: var n: i32;
  33. // CHECK:STDERR: ^~~~~~
  34. // CHECK:STDERR:
  35. var n: i32;
  36. }
  37. class AdaptWithFields {
  38. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+3]]:3: error: adapter with fields [AdaptWithFields]
  39. // CHECK:STDERR: adapt i32;
  40. // CHECK:STDERR: ^~~~~~~~~~
  41. adapt i32;
  42. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+4]]:7: note: first field declaration is here [AdaptWithFieldHere]
  43. // CHECK:STDERR: var a: i32;
  44. // CHECK:STDERR: ^~~~~~
  45. // CHECK:STDERR:
  46. var a: i32;
  47. var b: i32;
  48. var c: i32;
  49. }
  50. // --- fail_adapt_with_base_and_fields.carbon
  51. library "[[@TEST_NAME]]";
  52. base class Base {}
  53. class AdaptWithBaseAndFields {
  54. extend base: Base;
  55. var n: i32;
  56. // CHECK:STDERR: fail_adapt_with_base_and_fields.carbon:[[@LINE+6]]:3: error: adapter with base class [AdaptWithBase]
  57. // CHECK:STDERR: adapt {};
  58. // CHECK:STDERR: ^~~~~~~~~
  59. // CHECK:STDERR: fail_adapt_with_base_and_fields.carbon:[[@LINE-5]]:3: note: `base` declaration is here [AdaptWithBaseHere]
  60. // CHECK:STDERR: extend base: Base;
  61. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  62. adapt {};
  63. }
  64. // CHECK:STDOUT: --- fail_adapt_with_base.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  68. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  69. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  70. // CHECK:STDOUT: %AdaptWithBase: type = class_type @AdaptWithBase [template]
  71. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  72. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  73. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  74. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  75. // CHECK:STDOUT: %.5: type = unbound_element_type %AdaptWithBase, %Base [template]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: imports {
  79. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  80. // CHECK:STDOUT: .Int32 = %import_ref
  81. // CHECK:STDOUT: import Core//prelude
  82. // CHECK:STDOUT: import Core//prelude/operators
  83. // CHECK:STDOUT: import Core//prelude/types
  84. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  85. // CHECK:STDOUT: import Core//prelude/operators/as
  86. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  87. // CHECK:STDOUT: import Core//prelude/operators/comparison
  88. // CHECK:STDOUT: import Core//prelude/types/bool
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: file {
  94. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  95. // CHECK:STDOUT: .Core = imports.%Core
  96. // CHECK:STDOUT: .Base = %Base.decl
  97. // CHECK:STDOUT: .AdaptWithBase = %AdaptWithBase.decl
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %Core.import = import Core
  100. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  101. // CHECK:STDOUT: %AdaptWithBase.decl: type = class_decl @AdaptWithBase [template = constants.%AdaptWithBase] {} {}
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: class @Base {
  105. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !members:
  108. // CHECK:STDOUT: .Self = constants.%Base
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: class @AdaptWithBase {
  112. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  113. // CHECK:STDOUT: %.loc10_12.1: type = value_of_initializer %int.make_type_32 [template = i32]
  114. // CHECK:STDOUT: %.loc10_12.2: type = converted %int.make_type_32, %.loc10_12.1 [template = i32]
  115. // CHECK:STDOUT: adapt_decl i32
  116. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  117. // CHECK:STDOUT: %.loc15: %.5 = base_decl %Base, element0 [template]
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !members:
  120. // CHECK:STDOUT: .Self = constants.%AdaptWithBase
  121. // CHECK:STDOUT: .base = %.loc15
  122. // CHECK:STDOUT: extend name_scope2
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: --- fail_adapt_with_fields.carbon
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: constants {
  130. // CHECK:STDOUT: %AdaptWithField: type = class_type @AdaptWithField [template]
  131. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  132. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  133. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  134. // CHECK:STDOUT: %.2: type = unbound_element_type %AdaptWithField, i32 [template]
  135. // CHECK:STDOUT: %AdaptWithFields: type = class_type @AdaptWithFields [template]
  136. // CHECK:STDOUT: %.3: type = unbound_element_type %AdaptWithFields, i32 [template]
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: imports {
  140. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  141. // CHECK:STDOUT: .Int32 = %import_ref
  142. // CHECK:STDOUT: import Core//prelude
  143. // CHECK:STDOUT: import Core//prelude/operators
  144. // CHECK:STDOUT: import Core//prelude/types
  145. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  146. // CHECK:STDOUT: import Core//prelude/operators/as
  147. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  148. // CHECK:STDOUT: import Core//prelude/operators/comparison
  149. // CHECK:STDOUT: import Core//prelude/types/bool
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: file {
  155. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  156. // CHECK:STDOUT: .Core = imports.%Core
  157. // CHECK:STDOUT: .AdaptWithField = %AdaptWithField.decl
  158. // CHECK:STDOUT: .AdaptWithFields = %AdaptWithFields.decl
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %Core.import = import Core
  161. // CHECK:STDOUT: %AdaptWithField.decl: type = class_decl @AdaptWithField [template = constants.%AdaptWithField] {} {}
  162. // CHECK:STDOUT: %AdaptWithFields.decl: type = class_decl @AdaptWithFields [template = constants.%AdaptWithFields] {} {}
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: class @AdaptWithField {
  166. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  167. // CHECK:STDOUT: %.loc8_12.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  168. // CHECK:STDOUT: %.loc8_12.2: type = converted %int.make_type_32.loc8, %.loc8_12.1 [template = i32]
  169. // CHECK:STDOUT: adapt_decl i32
  170. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  171. // CHECK:STDOUT: %.loc13_10.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  172. // CHECK:STDOUT: %.loc13_10.2: type = converted %int.make_type_32.loc13, %.loc13_10.1 [template = i32]
  173. // CHECK:STDOUT: %.loc13_8: %.2 = field_decl n, element0 [template]
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: !members:
  176. // CHECK:STDOUT: .Self = constants.%AdaptWithField
  177. // CHECK:STDOUT: .n = %.loc13_8
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: class @AdaptWithFields {
  181. // CHECK:STDOUT: %int.make_type_32.loc20: init type = call constants.%Int32() [template = i32]
  182. // CHECK:STDOUT: %.loc20_12.1: type = value_of_initializer %int.make_type_32.loc20 [template = i32]
  183. // CHECK:STDOUT: %.loc20_12.2: type = converted %int.make_type_32.loc20, %.loc20_12.1 [template = i32]
  184. // CHECK:STDOUT: adapt_decl i32
  185. // CHECK:STDOUT: %int.make_type_32.loc25: init type = call constants.%Int32() [template = i32]
  186. // CHECK:STDOUT: %.loc25_10.1: type = value_of_initializer %int.make_type_32.loc25 [template = i32]
  187. // CHECK:STDOUT: %.loc25_10.2: type = converted %int.make_type_32.loc25, %.loc25_10.1 [template = i32]
  188. // CHECK:STDOUT: %.loc25_8: %.3 = field_decl a, element0 [template]
  189. // CHECK:STDOUT: %int.make_type_32.loc26: init type = call constants.%Int32() [template = i32]
  190. // CHECK:STDOUT: %.loc26_10.1: type = value_of_initializer %int.make_type_32.loc26 [template = i32]
  191. // CHECK:STDOUT: %.loc26_10.2: type = converted %int.make_type_32.loc26, %.loc26_10.1 [template = i32]
  192. // CHECK:STDOUT: %.loc26_8: %.3 = field_decl b, element1 [template]
  193. // CHECK:STDOUT: %int.make_type_32.loc27: init type = call constants.%Int32() [template = i32]
  194. // CHECK:STDOUT: %.loc27_10.1: type = value_of_initializer %int.make_type_32.loc27 [template = i32]
  195. // CHECK:STDOUT: %.loc27_10.2: type = converted %int.make_type_32.loc27, %.loc27_10.1 [template = i32]
  196. // CHECK:STDOUT: %.loc27_8: %.3 = field_decl c, element2 [template]
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: !members:
  199. // CHECK:STDOUT: .Self = constants.%AdaptWithFields
  200. // CHECK:STDOUT: .a = %.loc25_8
  201. // CHECK:STDOUT: .b = %.loc26_8
  202. // CHECK:STDOUT: .c = %.loc27_8
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: --- fail_adapt_with_base_and_fields.carbon
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: constants {
  210. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  211. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  212. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  213. // CHECK:STDOUT: %AdaptWithBaseAndFields: type = class_type @AdaptWithBaseAndFields [template]
  214. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  215. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  216. // CHECK:STDOUT: %.5: type = unbound_element_type %AdaptWithBaseAndFields, %Base [template]
  217. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  218. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  219. // CHECK:STDOUT: %.6: type = unbound_element_type %AdaptWithBaseAndFields, i32 [template]
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: imports {
  223. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  224. // CHECK:STDOUT: .Int32 = %import_ref
  225. // CHECK:STDOUT: import Core//prelude
  226. // CHECK:STDOUT: import Core//prelude/operators
  227. // CHECK:STDOUT: import Core//prelude/types
  228. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  229. // CHECK:STDOUT: import Core//prelude/operators/as
  230. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  231. // CHECK:STDOUT: import Core//prelude/operators/comparison
  232. // CHECK:STDOUT: import Core//prelude/types/bool
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: file {
  238. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  239. // CHECK:STDOUT: .Core = imports.%Core
  240. // CHECK:STDOUT: .Base = %Base.decl
  241. // CHECK:STDOUT: .AdaptWithBaseAndFields = %AdaptWithBaseAndFields.decl
  242. // CHECK:STDOUT: }
  243. // CHECK:STDOUT: %Core.import = import Core
  244. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  245. // CHECK:STDOUT: %AdaptWithBaseAndFields.decl: type = class_decl @AdaptWithBaseAndFields [template = constants.%AdaptWithBaseAndFields] {} {}
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: class @Base {
  249. // CHECK:STDOUT: %.loc4: <witness> = complete_type_witness %.1 [template = constants.%.2]
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: !members:
  252. // CHECK:STDOUT: .Self = constants.%Base
  253. // CHECK:STDOUT: }
  254. // CHECK:STDOUT:
  255. // CHECK:STDOUT: class @AdaptWithBaseAndFields {
  256. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  257. // CHECK:STDOUT: %.loc7: %.5 = base_decl %Base, element0 [template]
  258. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  259. // CHECK:STDOUT: %.loc8_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  260. // CHECK:STDOUT: %.loc8_10.2: type = converted %int.make_type_32, %.loc8_10.1 [template = i32]
  261. // CHECK:STDOUT: %.loc8_8: %.6 = field_decl n, element1 [template]
  262. // CHECK:STDOUT: %.loc15_10: %.1 = struct_literal ()
  263. // CHECK:STDOUT: %.loc15_11: type = converted %.loc15_10, constants.%.1 [template = constants.%.1]
  264. // CHECK:STDOUT: adapt_decl %.1
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: !members:
  267. // CHECK:STDOUT: .Self = constants.%AdaptWithBaseAndFields
  268. // CHECK:STDOUT: .base = %.loc7
  269. // CHECK:STDOUT: .n = %.loc8_8
  270. // CHECK:STDOUT: extend name_scope2
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT:
  273. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  274. // CHECK:STDOUT: