fail_adapt_with_subobjects.carbon 13 KB

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