fail_adapt_bad_decl.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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/adapter/fail_adapt_bad_decl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/adapter/fail_adapt_bad_decl.carbon
  10. // --- fail_not_type.carbon
  11. library "[[@TEST_NAME]]";
  12. class Bad {
  13. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `type` [ImplicitAsConversionFailure]
  14. // CHECK:STDERR: adapt 100;
  15. // CHECK:STDERR: ^~~~~~~~~~
  16. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  17. // CHECK:STDERR: adapt 100;
  18. // CHECK:STDERR: ^~~~~~~~~~
  19. // CHECK:STDERR:
  20. adapt 100;
  21. }
  22. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:18: error: member name `F` not found in `Bad` [MemberNameNotFoundInScope]
  23. // CHECK:STDERR: fn Use(b: Bad) { b.F(); }
  24. // CHECK:STDERR: ^~~
  25. // CHECK:STDERR:
  26. fn Use(b: Bad) { b.F(); }
  27. // --- fail_extend_not_type.carbon
  28. library "[[@TEST_NAME]]";
  29. class Bad {
  30. // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `type` [ImplicitAsConversionFailure]
  31. // CHECK:STDERR: extend adapt 100;
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  33. // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  34. // CHECK:STDERR: extend adapt 100;
  35. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  36. // CHECK:STDERR:
  37. extend adapt 100;
  38. }
  39. // No diagnostic here, we don't know what names Bad has.
  40. fn Use(b: Bad) { b.F(); }
  41. // --- fail_repeated.carbon
  42. library "[[@TEST_NAME]]";
  43. class MultipleAdapts {
  44. adapt ();
  45. // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
  46. // CHECK:STDERR: adapt {};
  47. // CHECK:STDERR: ^~~~~~~~~
  48. // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
  49. // CHECK:STDERR: adapt ();
  50. // CHECK:STDERR: ^~~~~~~~~
  51. // CHECK:STDERR:
  52. adapt {};
  53. }
  54. class MultipleAdaptsSameType {
  55. adapt ();
  56. // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
  57. // CHECK:STDERR: adapt ();
  58. // CHECK:STDERR: ^~~~~~~~~
  59. // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
  60. // CHECK:STDERR: adapt ();
  61. // CHECK:STDERR: ^~~~~~~~~
  62. // CHECK:STDERR:
  63. adapt ();
  64. }
  65. // --- fail_bad_scope.carbon
  66. library "[[@TEST_NAME]]";
  67. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:1: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
  68. // CHECK:STDERR: adapt {};
  69. // CHECK:STDERR: ^~~~~~~~~
  70. // CHECK:STDERR:
  71. adapt {};
  72. interface I {
  73. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:3: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
  74. // CHECK:STDERR: adapt {};
  75. // CHECK:STDERR: ^~~~~~~~~
  76. // CHECK:STDERR:
  77. adapt {};
  78. }
  79. class C {
  80. interface I {
  81. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:5: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
  82. // CHECK:STDERR: adapt {};
  83. // CHECK:STDERR: ^~~~~~~~~
  84. // CHECK:STDERR:
  85. adapt {};
  86. }
  87. }
  88. // CHECK:STDOUT: --- fail_not_type.carbon
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: constants {
  91. // CHECK:STDOUT: %Bad: type = class_type @Bad [template]
  92. // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template]
  93. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  94. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: imports {
  98. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  99. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  100. // CHECK:STDOUT: import Core//prelude
  101. // CHECK:STDOUT: import Core//prelude/...
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: file {
  106. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  107. // CHECK:STDOUT: .Core = imports.%Core
  108. // CHECK:STDOUT: .Bad = %Bad.decl
  109. // CHECK:STDOUT: .Use = %Use.decl
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %Core.import = import Core
  112. // CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
  113. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
  114. // CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
  115. // CHECK:STDOUT: %b.param_patt: %Bad = value_param_pattern %b.patt, runtime_param0
  116. // CHECK:STDOUT: } {
  117. // CHECK:STDOUT: %b.param: %Bad = value_param runtime_param0
  118. // CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
  119. // CHECK:STDOUT: %b: %Bad = bind_name b, %b.param
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: class @Bad {
  124. // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template = constants.%int_100]
  125. // CHECK:STDOUT: %.loc12: type = converted %int_100, <error> [template = <error>]
  126. // CHECK:STDOUT: adapt_decl <error> [template]
  127. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness <error> [template = <error>]
  128. // CHECK:STDOUT: complete_type_witness = %complete_type
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: !members:
  131. // CHECK:STDOUT: .Self = constants.%Bad
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
  135. // CHECK:STDOUT: !entry:
  136. // CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
  137. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  138. // CHECK:STDOUT: return
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: --- fail_extend_not_type.carbon
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: constants {
  144. // CHECK:STDOUT: %Bad: type = class_type @Bad [template]
  145. // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template]
  146. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  147. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: imports {
  151. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  152. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  153. // CHECK:STDOUT: import Core//prelude
  154. // CHECK:STDOUT: import Core//prelude/...
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: file {
  159. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  160. // CHECK:STDOUT: .Core = imports.%Core
  161. // CHECK:STDOUT: .Bad = %Bad.decl
  162. // CHECK:STDOUT: .Use = %Use.decl
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT: %Core.import = import Core
  165. // CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
  166. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
  167. // CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
  168. // CHECK:STDOUT: %b.param_patt: %Bad = value_param_pattern %b.patt, runtime_param0
  169. // CHECK:STDOUT: } {
  170. // CHECK:STDOUT: %b.param: %Bad = value_param runtime_param0
  171. // CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
  172. // CHECK:STDOUT: %b: %Bad = bind_name b, %b.param
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: class @Bad {
  177. // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template = constants.%int_100]
  178. // CHECK:STDOUT: %.loc12: type = converted %int_100, <error> [template = <error>]
  179. // CHECK:STDOUT: adapt_decl <error> [template]
  180. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness <error> [template = <error>]
  181. // CHECK:STDOUT: complete_type_witness = %complete_type
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Self = constants.%Bad
  185. // CHECK:STDOUT: extend <error>
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT:
  188. // CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
  189. // CHECK:STDOUT: !entry:
  190. // CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
  191. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  192. // CHECK:STDOUT: return
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: --- fail_repeated.carbon
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: constants {
  198. // CHECK:STDOUT: %MultipleAdapts: type = class_type @MultipleAdapts [template]
  199. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  200. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  201. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_tuple.type [template]
  202. // CHECK:STDOUT: %MultipleAdaptsSameType: type = class_type @MultipleAdaptsSameType [template]
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: imports {
  206. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  207. // CHECK:STDOUT: import Core//prelude
  208. // CHECK:STDOUT: import Core//prelude/...
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: file {
  213. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  214. // CHECK:STDOUT: .Core = imports.%Core
  215. // CHECK:STDOUT: .MultipleAdapts = %MultipleAdapts.decl
  216. // CHECK:STDOUT: .MultipleAdaptsSameType = %MultipleAdaptsSameType.decl
  217. // CHECK:STDOUT: }
  218. // CHECK:STDOUT: %Core.import = import Core
  219. // CHECK:STDOUT: %MultipleAdapts.decl: type = class_decl @MultipleAdapts [template = constants.%MultipleAdapts] {} {}
  220. // CHECK:STDOUT: %MultipleAdaptsSameType.decl: type = class_decl @MultipleAdaptsSameType [template = constants.%MultipleAdaptsSameType] {} {}
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: class @MultipleAdapts {
  224. // CHECK:STDOUT: %.loc5_10: %empty_tuple.type = tuple_literal ()
  225. // CHECK:STDOUT: %.loc5_11: type = converted %.loc5_10, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  226. // CHECK:STDOUT: adapt_decl %.loc5_11 [template]
  227. // CHECK:STDOUT: %.loc13: %empty_struct_type = struct_literal ()
  228. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_tuple.type [template = constants.%complete_type]
  229. // CHECK:STDOUT: complete_type_witness = %complete_type
  230. // CHECK:STDOUT:
  231. // CHECK:STDOUT: !members:
  232. // CHECK:STDOUT: .Self = constants.%MultipleAdapts
  233. // CHECK:STDOUT: }
  234. // CHECK:STDOUT:
  235. // CHECK:STDOUT: class @MultipleAdaptsSameType {
  236. // CHECK:STDOUT: %.loc17_10: %empty_tuple.type = tuple_literal ()
  237. // CHECK:STDOUT: %.loc17_11: type = converted %.loc17_10, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  238. // CHECK:STDOUT: adapt_decl %.loc17_11 [template]
  239. // CHECK:STDOUT: %.loc25: %empty_tuple.type = tuple_literal ()
  240. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_tuple.type [template = constants.%complete_type]
  241. // CHECK:STDOUT: complete_type_witness = %complete_type
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: !members:
  244. // CHECK:STDOUT: .Self = constants.%MultipleAdaptsSameType
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: --- fail_bad_scope.carbon
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: constants {
  250. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  251. // CHECK:STDOUT: %I.type.733: type = facet_type <@I.1> [template]
  252. // CHECK:STDOUT: %Self.826: %I.type.733 = bind_symbolic_name Self, 0 [symbolic]
  253. // CHECK:STDOUT: %C: type = class_type @C [template]
  254. // CHECK:STDOUT: %I.type.e30: type = facet_type <@I.2> [template]
  255. // CHECK:STDOUT: %Self.6ef: %I.type.e30 = bind_symbolic_name Self, 0 [symbolic]
  256. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  257. // CHECK:STDOUT: }
  258. // CHECK:STDOUT:
  259. // CHECK:STDOUT: imports {
  260. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  261. // CHECK:STDOUT: import Core//prelude
  262. // CHECK:STDOUT: import Core//prelude/...
  263. // CHECK:STDOUT: }
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: file {
  267. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  268. // CHECK:STDOUT: .Core = imports.%Core
  269. // CHECK:STDOUT: .I = %I.decl
  270. // CHECK:STDOUT: .C = %C.decl
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: %Core.import = import Core
  273. // CHECK:STDOUT: %.loc8: %empty_struct_type = struct_literal ()
  274. // CHECK:STDOUT: %I.decl: type = interface_decl @I.1 [template = constants.%I.type.733] {} {}
  275. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  276. // CHECK:STDOUT: }
  277. // CHECK:STDOUT:
  278. // CHECK:STDOUT: interface @I.1 {
  279. // CHECK:STDOUT: %Self: %I.type.733 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.826]
  280. // CHECK:STDOUT: %.loc15: %empty_struct_type = struct_literal ()
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: !members:
  283. // CHECK:STDOUT: .Self = %Self
  284. // CHECK:STDOUT: witness = ()
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: interface @I.2 {
  288. // CHECK:STDOUT: %Self: %I.type.e30 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.6ef]
  289. // CHECK:STDOUT: %.loc24: %empty_struct_type = struct_literal ()
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: !members:
  292. // CHECK:STDOUT: .Self = %Self
  293. // CHECK:STDOUT: witness = ()
  294. // CHECK:STDOUT: }
  295. // CHECK:STDOUT:
  296. // CHECK:STDOUT: class @C {
  297. // CHECK:STDOUT: %I.decl: type = interface_decl @I.2 [template = constants.%I.type.e30] {} {}
  298. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  299. // CHECK:STDOUT: complete_type_witness = %complete_type
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: !members:
  302. // CHECK:STDOUT: .Self = constants.%C
  303. // CHECK:STDOUT: .I = %I.decl
  304. // CHECK:STDOUT: }
  305. // CHECK:STDOUT: