fail_adapt_with_subobjects.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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" api;
  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" api;
  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" api;
  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: %.2: type = tuple_type () [template]
  67. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  68. // CHECK:STDOUT: %.4: type = unbound_element_type AdaptWithBase, Base [template]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: file {
  72. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  73. // CHECK:STDOUT: .Core = %Core
  74. // CHECK:STDOUT: .Base = %Base.decl
  75. // CHECK:STDOUT: .AdaptWithBase = %AdaptWithBase.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  78. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  79. // CHECK:STDOUT: %AdaptWithBase.decl: type = class_decl @AdaptWithBase [template = constants.%AdaptWithBase] {}
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: class @Base {
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .Self = constants.%Base
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: class @AdaptWithBase {
  88. // CHECK:STDOUT: adapt_decl i32
  89. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  90. // CHECK:STDOUT: %.loc15: <unbound element of class AdaptWithBase> = base_decl Base, element0 [template]
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !members:
  93. // CHECK:STDOUT: .Self = constants.%AdaptWithBase
  94. // CHECK:STDOUT: .base = %.loc15
  95. // CHECK:STDOUT: extend name_scope2
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: --- fail_adapt_with_fields.carbon
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: constants {
  101. // CHECK:STDOUT: %AdaptWithField: type = class_type @AdaptWithField [template]
  102. // CHECK:STDOUT: %.1: type = unbound_element_type AdaptWithField, i32 [template]
  103. // CHECK:STDOUT: %AdaptWithFields: type = class_type @AdaptWithFields [template]
  104. // CHECK:STDOUT: %.2: type = unbound_element_type AdaptWithFields, i32 [template]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: file {
  108. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  109. // CHECK:STDOUT: .Core = %Core
  110. // CHECK:STDOUT: .AdaptWithField = %AdaptWithField.decl
  111. // CHECK:STDOUT: .AdaptWithFields = %AdaptWithFields.decl
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  114. // CHECK:STDOUT: %AdaptWithField.decl: type = class_decl @AdaptWithField [template = constants.%AdaptWithField] {}
  115. // CHECK:STDOUT: %AdaptWithFields.decl: type = class_decl @AdaptWithFields [template = constants.%AdaptWithFields] {}
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: class @AdaptWithField {
  119. // CHECK:STDOUT: adapt_decl i32
  120. // CHECK:STDOUT: %.loc13: <unbound element of class AdaptWithField> = field_decl n, element0 [template]
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: !members:
  123. // CHECK:STDOUT: .Self = constants.%AdaptWithField
  124. // CHECK:STDOUT: .n = %.loc13
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: class @AdaptWithFields {
  128. // CHECK:STDOUT: adapt_decl i32
  129. // CHECK:STDOUT: %.loc25: <unbound element of class AdaptWithFields> = field_decl a, element0 [template]
  130. // CHECK:STDOUT: %.loc26: <unbound element of class AdaptWithFields> = field_decl b, element1 [template]
  131. // CHECK:STDOUT: %.loc27: <unbound element of class AdaptWithFields> = field_decl c, element2 [template]
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !members:
  134. // CHECK:STDOUT: .Self = constants.%AdaptWithFields
  135. // CHECK:STDOUT: .a = %.loc25
  136. // CHECK:STDOUT: .b = %.loc26
  137. // CHECK:STDOUT: .c = %.loc27
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: --- fail_adapt_with_base_and_fields.carbon
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: constants {
  143. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  144. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  145. // CHECK:STDOUT: %AdaptWithBaseAndFields: type = class_type @AdaptWithBaseAndFields [template]
  146. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  147. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  148. // CHECK:STDOUT: %.4: type = unbound_element_type AdaptWithBaseAndFields, Base [template]
  149. // CHECK:STDOUT: %.5: type = unbound_element_type AdaptWithBaseAndFields, i32 [template]
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: file {
  153. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  154. // CHECK:STDOUT: .Core = %Core
  155. // CHECK:STDOUT: .Base = %Base.decl
  156. // CHECK:STDOUT: .AdaptWithBaseAndFields = %AdaptWithBaseAndFields.decl
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  159. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {}
  160. // CHECK:STDOUT: %AdaptWithBaseAndFields.decl: type = class_decl @AdaptWithBaseAndFields [template = constants.%AdaptWithBaseAndFields] {}
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: class @Base {
  164. // CHECK:STDOUT: !members:
  165. // CHECK:STDOUT: .Self = constants.%Base
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: class @AdaptWithBaseAndFields {
  169. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [template = constants.%Base]
  170. // CHECK:STDOUT: %.loc7: <unbound element of class AdaptWithBaseAndFields> = base_decl Base, element0 [template]
  171. // CHECK:STDOUT: %.loc8: <unbound element of class AdaptWithBaseAndFields> = field_decl n, element1 [template]
  172. // CHECK:STDOUT: %.loc15_10.1: {} = struct_literal ()
  173. // CHECK:STDOUT: %.loc15_10.2: type = converted %.loc15_10.1, constants.%.1 [template = constants.%.1]
  174. // CHECK:STDOUT: adapt_decl {}
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: !members:
  177. // CHECK:STDOUT: .Self = constants.%AdaptWithBaseAndFields
  178. // CHECK:STDOUT: .base = %.loc7
  179. // CHECK:STDOUT: .n = %.loc8
  180. // CHECK:STDOUT: extend name_scope2
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT: