fail_adapt_with_subobjects.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. // --- fail_adapt_with_base.carbon
  7. library "fail_adapt_with_base";
  8. base class Base {}
  9. class AdaptWithBase {
  10. // CHECK:STDERR: fail_adapt_with_base.carbon:[[@LINE+3]]:3: ERROR: Adapter cannot have a base class.
  11. // CHECK:STDERR: adapt i32;
  12. // CHECK:STDERR: ^~~~~~~~~~
  13. adapt i32;
  14. // CHECK:STDERR: fail_adapt_with_base.carbon:[[@LINE+4]]:3: `base` declaration is here.
  15. // CHECK:STDERR: extend base: Base;
  16. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  17. // CHECK:STDERR:
  18. extend base: Base;
  19. }
  20. // --- fail_adapt_with_fields.carbon
  21. library "fail_adapt_with_fields";
  22. class AdaptWithField {
  23. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+3]]:3: ERROR: Adapter cannot have fields.
  24. // CHECK:STDERR: adapt i32;
  25. // CHECK:STDERR: ^~~~~~~~~~
  26. adapt i32;
  27. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+4]]:7: First field declaration is here.
  28. // CHECK:STDERR: var n: i32;
  29. // CHECK:STDERR: ^~~~~~
  30. // CHECK:STDERR:
  31. var n: i32;
  32. }
  33. class AdaptWithFields {
  34. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+3]]:3: ERROR: Adapter cannot have fields.
  35. // CHECK:STDERR: adapt i32;
  36. // CHECK:STDERR: ^~~~~~~~~~
  37. adapt i32;
  38. // CHECK:STDERR: fail_adapt_with_fields.carbon:[[@LINE+4]]:7: First field declaration is here.
  39. // CHECK:STDERR: var a: i32;
  40. // CHECK:STDERR: ^~~~~~
  41. // CHECK:STDERR:
  42. var a: i32;
  43. var b: i32;
  44. var c: i32;
  45. }
  46. // --- fail_adapt_with_base_and_fields.carbon
  47. library "fail_adapt_with_base_and_fields";
  48. base class Base {}
  49. class AdaptWithBaseAndFields {
  50. extend base: Base;
  51. var n: i32;
  52. // CHECK:STDERR: fail_adapt_with_base_and_fields.carbon:[[@LINE+6]]:3: ERROR: Adapter cannot have a base class.
  53. // CHECK:STDERR: adapt {};
  54. // CHECK:STDERR: ^~~~~~~~~
  55. // CHECK:STDERR: fail_adapt_with_base_and_fields.carbon:[[@LINE-5]]:3: `base` declaration is here.
  56. // CHECK:STDERR: extend base: Base;
  57. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  58. adapt {};
  59. }
  60. // CHECK:STDOUT: --- fail_adapt_with_base.carbon
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: constants {
  63. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  64. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  65. // CHECK:STDOUT: %AdaptWithBase: type = class_type @AdaptWithBase [template]
  66. // CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
  67. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  68. // CHECK:STDOUT: %struct: Int32 = struct_value () [template]
  69. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  70. // CHECK:STDOUT: %.4: type = unbound_element_type AdaptWithBase, Base [template]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: file {
  74. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  75. // CHECK:STDOUT: .Core = %Core
  76. // CHECK:STDOUT: .Base = %Base.decl
  77. // CHECK:STDOUT: .AdaptWithBase = %AdaptWithBase.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  80. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  81. // CHECK:STDOUT: %AdaptWithBase.decl: type = class_decl @AdaptWithBase [template = constants.%AdaptWithBase] {}
  82. // CHECK:STDOUT: %import_ref: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: class @Base {
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = constants.%Base
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @AdaptWithBase {
  91. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%struct() [template = i32]
  92. // CHECK:STDOUT: %.loc10_12.1: type = value_of_initializer %int.make_type_32 [template = i32]
  93. // CHECK:STDOUT: %.loc10_12.2: type = converted %int.make_type_32, %.loc10_12.1 [template = i32]
  94. // CHECK:STDOUT: adapt_decl i32
  95. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  96. // CHECK:STDOUT: %.loc15: <unbound element of class AdaptWithBase> = base_decl Base, element0 [template]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = constants.%AdaptWithBase
  100. // CHECK:STDOUT: .base = %.loc15
  101. // CHECK:STDOUT: extend name_scope2
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: --- fail_adapt_with_fields.carbon
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: constants {
  109. // CHECK:STDOUT: %AdaptWithField: type = class_type @AdaptWithField [template]
  110. // CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
  111. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  112. // CHECK:STDOUT: %struct: Int32 = struct_value () [template]
  113. // CHECK:STDOUT: %.2: type = unbound_element_type AdaptWithField, i32 [template]
  114. // CHECK:STDOUT: %AdaptWithFields: type = class_type @AdaptWithFields [template]
  115. // CHECK:STDOUT: %.3: type = unbound_element_type AdaptWithFields, i32 [template]
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: file {
  119. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  120. // CHECK:STDOUT: .Core = %Core
  121. // CHECK:STDOUT: .AdaptWithField = %AdaptWithField.decl
  122. // CHECK:STDOUT: .AdaptWithFields = %AdaptWithFields.decl
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  125. // CHECK:STDOUT: %AdaptWithField.decl: type = class_decl @AdaptWithField [template = constants.%AdaptWithField] {}
  126. // CHECK:STDOUT: %import_ref.1: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  127. // CHECK:STDOUT: %import_ref.2: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  128. // CHECK:STDOUT: %AdaptWithFields.decl: type = class_decl @AdaptWithFields [template = constants.%AdaptWithFields] {}
  129. // CHECK:STDOUT: %import_ref.3: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  130. // CHECK:STDOUT: %import_ref.4: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  131. // CHECK:STDOUT: %import_ref.5: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  132. // CHECK:STDOUT: %import_ref.6: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: class @AdaptWithField {
  136. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%struct() [template = i32]
  137. // CHECK:STDOUT: %.loc8_12.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  138. // CHECK:STDOUT: %.loc8_12.2: type = converted %int.make_type_32.loc8, %.loc8_12.1 [template = i32]
  139. // CHECK:STDOUT: adapt_decl i32
  140. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%struct() [template = i32]
  141. // CHECK:STDOUT: %.loc13_10.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  142. // CHECK:STDOUT: %.loc13_10.2: type = converted %int.make_type_32.loc13, %.loc13_10.1 [template = i32]
  143. // CHECK:STDOUT: %.loc13_8: <unbound element of class AdaptWithField> = field_decl n, element0 [template]
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: !members:
  146. // CHECK:STDOUT: .Self = constants.%AdaptWithField
  147. // CHECK:STDOUT: .n = %.loc13_8
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: class @AdaptWithFields {
  151. // CHECK:STDOUT: %int.make_type_32.loc20: init type = call constants.%struct() [template = i32]
  152. // CHECK:STDOUT: %.loc20_12.1: type = value_of_initializer %int.make_type_32.loc20 [template = i32]
  153. // CHECK:STDOUT: %.loc20_12.2: type = converted %int.make_type_32.loc20, %.loc20_12.1 [template = i32]
  154. // CHECK:STDOUT: adapt_decl i32
  155. // CHECK:STDOUT: %int.make_type_32.loc25: init type = call constants.%struct() [template = i32]
  156. // CHECK:STDOUT: %.loc25_10.1: type = value_of_initializer %int.make_type_32.loc25 [template = i32]
  157. // CHECK:STDOUT: %.loc25_10.2: type = converted %int.make_type_32.loc25, %.loc25_10.1 [template = i32]
  158. // CHECK:STDOUT: %.loc25_8: <unbound element of class AdaptWithFields> = field_decl a, element0 [template]
  159. // CHECK:STDOUT: %int.make_type_32.loc26: init type = call constants.%struct() [template = i32]
  160. // CHECK:STDOUT: %.loc26_10.1: type = value_of_initializer %int.make_type_32.loc26 [template = i32]
  161. // CHECK:STDOUT: %.loc26_10.2: type = converted %int.make_type_32.loc26, %.loc26_10.1 [template = i32]
  162. // CHECK:STDOUT: %.loc26_8: <unbound element of class AdaptWithFields> = field_decl b, element1 [template]
  163. // CHECK:STDOUT: %int.make_type_32.loc27: init type = call constants.%struct() [template = i32]
  164. // CHECK:STDOUT: %.loc27_10.1: type = value_of_initializer %int.make_type_32.loc27 [template = i32]
  165. // CHECK:STDOUT: %.loc27_10.2: type = converted %int.make_type_32.loc27, %.loc27_10.1 [template = i32]
  166. // CHECK:STDOUT: %.loc27_8: <unbound element of class AdaptWithFields> = field_decl c, element2 [template]
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: !members:
  169. // CHECK:STDOUT: .Self = constants.%AdaptWithFields
  170. // CHECK:STDOUT: .a = %.loc25_8
  171. // CHECK:STDOUT: .b = %.loc26_8
  172. // CHECK:STDOUT: .c = %.loc27_8
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: --- fail_adapt_with_base_and_fields.carbon
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: constants {
  180. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  181. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  182. // CHECK:STDOUT: %AdaptWithBaseAndFields: type = class_type @AdaptWithBaseAndFields [template]
  183. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  184. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  185. // CHECK:STDOUT: %.4: type = unbound_element_type AdaptWithBaseAndFields, Base [template]
  186. // CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
  187. // CHECK:STDOUT: %struct: Int32 = struct_value () [template]
  188. // CHECK:STDOUT: %.5: type = unbound_element_type AdaptWithBaseAndFields, i32 [template]
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: file {
  192. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  193. // CHECK:STDOUT: .Core = %Core
  194. // CHECK:STDOUT: .Base = %Base.decl
  195. // CHECK:STDOUT: .AdaptWithBaseAndFields = %AdaptWithBaseAndFields.decl
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  198. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  199. // CHECK:STDOUT: %AdaptWithBaseAndFields.decl: type = class_decl @AdaptWithBaseAndFields [template = constants.%AdaptWithBaseAndFields] {}
  200. // CHECK:STDOUT: %import_ref: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct]
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: class @Base {
  204. // CHECK:STDOUT: !members:
  205. // CHECK:STDOUT: .Self = constants.%Base
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: class @AdaptWithBaseAndFields {
  209. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  210. // CHECK:STDOUT: %.loc7: <unbound element of class AdaptWithBaseAndFields> = base_decl Base, element0 [template]
  211. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%struct() [template = i32]
  212. // CHECK:STDOUT: %.loc8_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  213. // CHECK:STDOUT: %.loc8_10.2: type = converted %int.make_type_32, %.loc8_10.1 [template = i32]
  214. // CHECK:STDOUT: %.loc8_8: <unbound element of class AdaptWithBaseAndFields> = field_decl n, element1 [template]
  215. // CHECK:STDOUT: %.loc15_10: {} = struct_literal ()
  216. // CHECK:STDOUT: %.loc15_11: type = converted %.loc15_10, constants.%.1 [template = constants.%.1]
  217. // CHECK:STDOUT: adapt_decl {}
  218. // CHECK:STDOUT:
  219. // CHECK:STDOUT: !members:
  220. // CHECK:STDOUT: .Self = constants.%AdaptWithBaseAndFields
  221. // CHECK:STDOUT: .base = %.loc7
  222. // CHECK:STDOUT: .n = %.loc8_8
  223. // CHECK:STDOUT: extend name_scope2
  224. // CHECK:STDOUT: }
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  227. // CHECK:STDOUT: