facet_assoc_const.carbon 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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/facet_types.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/facet_assoc_const.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/facet_assoc_const.carbon
  12. // --- success.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I { let T:! type; }
  15. fn F(T:! I where .T = {}) {}
  16. // --- success_associated.carbon
  17. library "[[@TEST_NAME]]";
  18. interface I { let T:! type; let U:! type; }
  19. fn F(T:! I where .T = .U) {}
  20. // --- fail_two_different.carbon
  21. library "[[@TEST_NAME]]";
  22. interface L { let W:! type; }
  23. // CHECK:STDERR: fail_two_different.carbon:[[@LINE+4]]:10: error: associated constant `.(L.W)` given two different values `{}` and `()` [AssociatedConstantWithDifferentValues]
  24. // CHECK:STDERR: fn F(T:! L where .W = {} and .W = ()) {}
  25. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. fn F(T:! L where .W = {} and .W = ()) {}
  28. // --- fail_two_different_first_associated.carbon
  29. library "[[@TEST_NAME]]";
  30. interface L { let W:! type; let X:! type; }
  31. // CHECK:STDERR: fail_two_different_first_associated.carbon:[[@LINE+4]]:10: error: associated constant `.(L.W)` given two different values `.(L.X)` and `()` [AssociatedConstantWithDifferentValues]
  32. // CHECK:STDERR: fn F(T:! L where .W = .X and .W = ()) {}
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. // CHECK:STDERR:
  35. fn F(T:! L where .W = .X and .W = ()) {}
  36. // --- fail_two_different_second_associated.carbon
  37. library "[[@TEST_NAME]]";
  38. interface L { let W:! type; let X:! type; }
  39. // CHECK:STDERR: fail_two_different_second_associated.carbon:[[@LINE+4]]:10: error: associated constant `.(L.W)` given two different values `()` and `.(L.X)` [AssociatedConstantWithDifferentValues]
  40. // CHECK:STDERR: fn F(T:! L where .W = () and .W = .X) {}
  41. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. // CHECK:STDERR:
  43. fn F(T:! L where .W = () and .W = .X) {}
  44. // --- fail_two_different_first_bad.carbon
  45. library "[[@TEST_NAME]]";
  46. interface L { let W:! type; }
  47. // CHECK:STDERR: fail_two_different_first_bad.carbon:[[@LINE+4]]:23: error: name `BAD5` not found [NameNotFound]
  48. // CHECK:STDERR: fn F(T:! L where .W = BAD5 and .W = ()) {}
  49. // CHECK:STDERR: ^~~~
  50. // CHECK:STDERR:
  51. fn F(T:! L where .W = BAD5 and .W = ()) {}
  52. // --- fail_two_different_second_bad.carbon
  53. library "[[@TEST_NAME]]";
  54. interface L { let W:! type; }
  55. // CHECK:STDERR: fail_two_different_second_bad.carbon:[[@LINE+4]]:35: error: name `BAD6` not found [NameNotFound]
  56. // CHECK:STDERR: fn F(T:! L where .W = {} and .W = BAD6) {}
  57. // CHECK:STDERR: ^~~~
  58. // CHECK:STDERR:
  59. fn F(T:! L where .W = {} and .W = BAD6) {}
  60. // --- fail_two_different_both_bad.carbon
  61. library "[[@TEST_NAME]]";
  62. interface L { let W:! type; }
  63. // CHECK:STDERR: fail_two_different_both_bad.carbon:[[@LINE+8]]:23: error: name `BAD7` not found [NameNotFound]
  64. // CHECK:STDERR: fn F(T:! L where .W = BAD7 and .W = BAD8) {}
  65. // CHECK:STDERR: ^~~~
  66. // CHECK:STDERR:
  67. // CHECK:STDERR: fail_two_different_both_bad.carbon:[[@LINE+4]]:37: error: name `BAD8` not found [NameNotFound]
  68. // CHECK:STDERR: fn F(T:! L where .W = BAD7 and .W = BAD8) {}
  69. // CHECK:STDERR: ^~~~
  70. // CHECK:STDERR:
  71. fn F(T:! L where .W = BAD7 and .W = BAD8) {}
  72. // --- fail_two_different_combined_from_bitand.carbon
  73. library "[[@TEST_NAME]]";
  74. interface L { let W:! type; }
  75. // CHECK:STDERR: fail_two_different_combined_from_bitand.carbon:[[@LINE+4]]:10: error: associated constant `.(L.W)` given two different values `{}` and `()` [AssociatedConstantWithDifferentValues]
  76. // CHECK:STDERR: fn F(T:! (L where .W = {}) & (L where .W = ())) {}
  77. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. // CHECK:STDERR:
  79. fn F(T:! (L where .W = {}) & (L where .W = ())) {}
  80. // --- two_different_combined_from_impl_and_facet.carbon
  81. library "[[@TEST_NAME]]";
  82. interface L { let W:! type; }
  83. interface M {}
  84. impl forall [T:! M] T as L where .W = () {}
  85. fn F(T:! M & (L where .W = {})) {}
  86. class C;
  87. impl C as L where .W = {} {}
  88. impl C as M {}
  89. fn G() {
  90. F(C);
  91. }
  92. // --- fail_two_different_combined_from_final_impl_and_facet.carbon
  93. library "[[@TEST_NAME]]";
  94. interface L { let W:! type; }
  95. interface M {}
  96. final impl forall [T:! M] T as L where .W = () {}
  97. fn G(T:! M & L, a: T.W) -> () { return a; }
  98. fn H(T:! L where .W = {}, a: T.W) -> {} { return a; }
  99. fn F(T:! M & (L where .W = {}), a: T.W) {
  100. // TODO: One of `b` or `c` must fail, because `T.W` is either found to be `()` from
  101. // the impl or `{}` from the facet type of T.
  102. let b: () = G(T, a);
  103. // CHECK:STDERR: fail_two_different_combined_from_final_impl_and_facet.carbon:[[@LINE+10]]:15: error: cannot implicitly convert expression of type `()` to `{}` [ConversionFailure]
  104. // CHECK:STDERR: let c: {} = H(T, a);
  105. // CHECK:STDERR: ^~~~~~~
  106. // CHECK:STDERR: fail_two_different_combined_from_final_impl_and_facet.carbon:[[@LINE+7]]:15: note: type `()` does not implement interface `Core.ImplicitAs({})` [MissingImplInMemberAccessNote]
  107. // CHECK:STDERR: let c: {} = H(T, a);
  108. // CHECK:STDERR: ^~~~~~~
  109. // CHECK:STDERR: fail_two_different_combined_from_final_impl_and_facet.carbon:[[@LINE-13]]:1: note: while deducing parameters of generic declared here [DeductionGenericHere]
  110. // CHECK:STDERR: fn H(T:! L where .W = {}, a: T.W) -> {} { return a; }
  111. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112. // CHECK:STDERR:
  113. let c: {} = H(T, a);
  114. }
  115. // --- fail_many_different.carbon
  116. library "[[@TEST_NAME]]";
  117. interface L { let W:! type; }
  118. // CHECK:STDERR: fail_many_different.carbon:[[@LINE+4]]:10: error: associated constant `.(L.W)` given two different values `((), (), ())` and `({}, (), ())` [AssociatedConstantWithDifferentValues]
  119. // CHECK:STDERR: fn G(T:! L where .W = ((), (), ()) and .W = ({}, (), ()) and .W = ({}, {}, ()) and .W = ({}, (), {})) {}
  120. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. // CHECK:STDERR:
  122. fn G(T:! L where .W = ((), (), ()) and .W = ({}, (), ()) and .W = ({}, {}, ()) and .W = ({}, (), {})) {}
  123. // --- rewrite_uses_second_facet.carbon
  124. library "[[@TEST_NAME]]";
  125. interface M { let X:! type; let Y:! type; }
  126. fn F(T:! M where .X = (), U:! M where .Y = T.X) -> U.Y {
  127. return ();
  128. }
  129. // --- fail_rewrite_conflicts_with_second_facet.carbon
  130. library "[[@TEST_NAME]]";
  131. interface M { let X:! type; let Y:! type; }
  132. // CHECK:STDERR: fail_rewrite_conflicts_with_second_facet.carbon:[[@LINE+4]]:31: error: associated constant `.(M.Y)` given two different values `T.(M.X)` and `.(M.X)` [AssociatedConstantWithDifferentValues]
  133. // CHECK:STDERR: fn F(T:! M where .X = (), U:! M where .Y = T.X and .Y = .X) {}
  134. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. // CHECK:STDERR:
  136. fn F(T:! M where .X = (), U:! M where .Y = T.X and .Y = .X) {}
  137. // --- repeated.carbon
  138. library "[[@TEST_NAME]]";
  139. interface M { let X:! type; }
  140. fn F(T:! M where .X = {} and .X = {}) {}
  141. fn G(T:! M where .X = {}) {
  142. F(T);
  143. }
  144. // --- repeated_associated.carbon
  145. library "[[@TEST_NAME]]";
  146. interface M { let X:! type; let Y:! type; }
  147. fn F(T:! M where .X = .Y and .X = .Y) {}
  148. fn G(T:! M where .X = () and .Y = ()) {
  149. F(T);
  150. }
  151. // --- repeated_concrete_value_and_associated.carbon
  152. library "[[@TEST_NAME]]";
  153. interface M { let X:! type; let Y:! type; }
  154. fn F1(T:! M where .X = () and .Y = .X and .X = .Y) {}
  155. fn F2(T:! M where .X = () and .X = .X) {}
  156. fn G(T:! M where .X = () and .Y = ()) {
  157. F1(T);
  158. F2(T);
  159. }
  160. // --- repeated_with_bitand.carbon
  161. library "[[@TEST_NAME]]";
  162. interface M { let X:! type; let Y:! type; }
  163. fn F1(T:! (M where .X = .Y) & (M where .X = .Y and .Y = ())) -> T.X {
  164. return ();
  165. }
  166. fn F2(T:! (M where .X = .Y and .Y = ()) & (M where .X = .Y)) -> T.X {
  167. return ();
  168. }
  169. // --- fail_repeated_and_different.carbon
  170. library "[[@TEST_NAME]]";
  171. interface M { let X:! type; }
  172. // CHECK:STDERR: fail_repeated_and_different.carbon:[[@LINE+4]]:10: error: associated constant `.(M.X)` given two different values `{}` and `()` [AssociatedConstantWithDifferentValues]
  173. // CHECK:STDERR: fn F(T:! M where .X = {} and .X = () and .X = {}) {}
  174. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. // CHECK:STDERR:
  176. fn F(T:! M where .X = {} and .X = () and .X = {}) {}
  177. // --- fail_cycle_single.carbon
  178. library "[[@TEST_NAME]]";
  179. interface M { let X:! type; }
  180. // This fails because it resolves to `.X = .X` which is cyclical.
  181. //
  182. // CHECK:STDERR: fail_cycle_single.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(M.X)` [FacetTypeConstraintCycle]
  183. // CHECK:STDERR: fn F(T:! M where .X = .X) {}
  184. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  185. // CHECK:STDERR:
  186. fn F(T:! M where .X = .X) {}
  187. // Even though `.X = ()` is specified, the rewrites are resolved left to right
  188. // and a cycle `.X = .X` is found first.
  189. //
  190. // CHECK:STDERR: fail_cycle_single.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(M.X)` [FacetTypeConstraintCycle]
  191. // CHECK:STDERR: fn G(T:! M where .X = .X and .X = ()) {}
  192. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  193. // CHECK:STDERR:
  194. fn G(T:! M where .X = .X and .X = ()) {}
  195. // --- fail_cycle.carbon
  196. library "[[@TEST_NAME]]";
  197. interface M { let X:! type; let Y:! type; let Z:! type; }
  198. // This fails because it resolves to `.X = .X` which is cyclical.
  199. // The value of .X and .Y becomes <error> but .Z is still valid.
  200. //
  201. //@dump-sem-ir-begin
  202. // CHECK:STDERR: fail_cycle.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(M.X)` [FacetTypeConstraintCycle]
  203. // CHECK:STDERR: fn F(T:! M where .X = .Y and .Y = .X and .Z = ()) {}
  204. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  205. // CHECK:STDERR:
  206. fn F(T:! M where .X = .Y and .Y = .X and .Z = ()) {}
  207. //@dump-sem-ir-end
  208. // --- fail_cycle_between_interfaces.carbon
  209. library "[[@TEST_NAME]]";
  210. interface I {
  211. let X1:! type;
  212. let X2:! type;
  213. }
  214. interface J {
  215. let X3:! type;
  216. }
  217. // This fails because it resolves to `.X1 = .X1` which is cyclical.
  218. //
  219. // CHECK:STDERR: fail_cycle_between_interfaces.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(I.X1)` [FacetTypeConstraintCycle]
  220. // CHECK:STDERR: fn G(T:! I & J where .X1 = .X3 and .X2 = .X1 and .X3 = .X2) {}
  221. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222. // CHECK:STDERR:
  223. fn G(T:! I & J where .X1 = .X3 and .X2 = .X1 and .X3 = .X2) {}
  224. // --- fail_indirect_cycle.carbon
  225. library "[[@TEST_NAME]]";
  226. interface I {
  227. let X1:! type;
  228. let X2:! type;
  229. }
  230. // This fails because it resolves to `.X1 = .X1**` which is cyclical.
  231. //
  232. // CHECK:STDERR: fail_indirect_cycle.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(I.X1)` [FacetTypeConstraintCycle]
  233. // CHECK:STDERR: fn F(T:! I where .X1 = .X2* and .X2 = .X1*);
  234. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  235. // CHECK:STDERR:
  236. fn F(T:! I where .X1 = .X2* and .X2 = .X1*);
  237. class C(T:! type);
  238. // This fails because it resolves to `.X1 = C(C(.X1))` which is cyclical.
  239. //
  240. // CHECK:STDERR: fail_indirect_cycle.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(I.X1)` [FacetTypeConstraintCycle]
  241. // CHECK:STDERR: fn G(T:! I where .X1 = C(.X2) and .X2 = C(.X1));
  242. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243. // CHECK:STDERR:
  244. fn G(T:! I where .X1 = C(.X2) and .X2 = C(.X1));
  245. // --- fail_complex_indirect_cycle.carbon
  246. library "[[@TEST_NAME]]";
  247. interface I {
  248. let X1:! type;
  249. let X2:! type;
  250. let X3:! type;
  251. }
  252. class C(T:! type, U:! type);
  253. // This fails because it resolves to `.X1 = C(C(.X3, .X1), .X3)` which is
  254. // cyclical.
  255. //
  256. // CHECK:STDERR: fail_complex_indirect_cycle.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(I.X1)` [FacetTypeConstraintCycle]
  257. // CHECK:STDERR: fn F(T:! I where .X1 = C(.X2, .X3) and .X2 = C(.X3, .X1));
  258. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  259. // CHECK:STDERR:
  260. fn F(T:! I where .X1 = C(.X2, .X3) and .X2 = C(.X3, .X1));
  261. // --- exponential_large.carbon
  262. library "[[@TEST_NAME]]";
  263. interface Z {
  264. let T0:! type;
  265. let T1:! type;
  266. let T2:! type;
  267. let T3:! type;
  268. let T4:! type;
  269. let T5:! type;
  270. let T6:! type;
  271. let T7:! type;
  272. let T8:! type;
  273. let T9:! type;
  274. }
  275. // A naive attempt to resolve the rewrite rules will run take minutes to
  276. // complete, since the resulting RHS values are exponential in size, and a naive
  277. // approach can recursively rebuild the RHS values from the ground up
  278. // repeatedly.
  279. fn F(
  280. T:! Z where
  281. .T0 = (.T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1) and
  282. .T1 = (.T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2) and
  283. .T2 = (.T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3) and
  284. .T3 = (.T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4) and
  285. .T4 = (.T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5) and
  286. .T5 = (.T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6) and
  287. .T6 = (.T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7) and
  288. .T7 = (.T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8) and
  289. .T8 = (.T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9) and
  290. .T9 = ()
  291. );
  292. // --- fail_exponential_large_cycle.carbon
  293. library "[[@TEST_NAME]]";
  294. interface Z {
  295. let T0:! type;
  296. let T1:! type;
  297. let T2:! type;
  298. let T3:! type;
  299. let T4:! type;
  300. let T5:! type;
  301. let T6:! type;
  302. let T7:! type;
  303. let T8:! type;
  304. let T9:! type;
  305. }
  306. // A naive attempt to resolve the rewrite rules will run take minutes to
  307. // complete, since the resulting RHS values are exponential in size, and a naive
  308. // approach can recursively rebuild the RHS values from the ground up
  309. // repeatedly.
  310. fn F(
  311. // CHECK:STDERR: fail_exponential_large_cycle.carbon:[[@LINE+4]]:9: error: found cycle in facet type constraint for `.(Z.T9)` [FacetTypeConstraintCycle]
  312. // CHECK:STDERR: T:! Z where
  313. // CHECK:STDERR: ^~~~~~~
  314. // CHECK:STDERR:
  315. T:! Z where
  316. .T9 = .T0 and
  317. .T8 = (.T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9, .T9) and
  318. .T7 = (.T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8, .T8) and
  319. .T6 = (.T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7, .T7) and
  320. .T5 = (.T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6, .T6) and
  321. .T4 = (.T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5, .T5) and
  322. .T3 = (.T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4, .T4) and
  323. .T2 = (.T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3, .T3) and
  324. .T1 = (.T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2, .T2) and
  325. .T0 = (.T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1, .T1)
  326. );
  327. // --- non-type.carbon
  328. library "[[@TEST_NAME]]";
  329. interface N {
  330. let Y:! {.a: {}};
  331. }
  332. fn F(T:! N where .Y = {.a = {}}) { }
  333. // --- non-type_repeated.carbon
  334. library "[[@TEST_NAME]]";
  335. interface N {
  336. let Y:! {.a: {}};
  337. }
  338. fn F(T:! N where .Y = {.a = {}} and .Y = {.a = {}}) { }
  339. // --- fail_non-type_different.carbon
  340. library "[[@TEST_NAME]]";
  341. interface N {
  342. let Y:! {.a: type};
  343. }
  344. // CHECK:STDERR: fail_non-type_different.carbon:[[@LINE+4]]:10: error: associated constant `.(N.Y)` given two different values `{.a = {}}` and `{.a = ()}` [AssociatedConstantWithDifferentValues]
  345. // CHECK:STDERR: fn F(T:! N where .Y = {.a = {}} and .Y = {.a = ()}) {}
  346. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  347. // CHECK:STDERR:
  348. fn F(T:! N where .Y = {.a = {}} and .Y = {.a = ()}) {}
  349. // --- fail_todo_cycle_through_self_reference.carbon
  350. library "[[@TEST_NAME]]";
  351. interface Z {
  352. let T:! type;
  353. // TODO: This should not be an error.
  354. //
  355. // CHECK:STDERR: fail_todo_cycle_through_self_reference.carbon:[[@LINE+7]]:11: error: associated constant has incomplete type `Z` [IncompleteTypeInAssociatedConstantDecl]
  356. // CHECK:STDERR: let U:! Z;
  357. // CHECK:STDERR: ^
  358. // CHECK:STDERR: fail_todo_cycle_through_self_reference.carbon:[[@LINE-7]]:1: note: interface is currently being defined [InterfaceIncompleteWithinDefinition]
  359. // CHECK:STDERR: interface Z {
  360. // CHECK:STDERR: ^~~~~~~~~~~~~
  361. // CHECK:STDERR:
  362. let U:! Z;
  363. }
  364. // TODO: Should be diagnosed as a cycle.
  365. fn F(A:! Z where .T = .U.T and .U = .Self) {}
  366. // --- fail_todo_reference_same_constant_in_different_self.carbon
  367. library "[[@TEST_NAME]]";
  368. interface Z {
  369. let T:! type;
  370. // TODO: This should not be an error.
  371. //
  372. // CHECK:STDERR: fail_todo_reference_same_constant_in_different_self.carbon:[[@LINE+7]]:11: error: associated constant has incomplete type `Z` [IncompleteTypeInAssociatedConstantDecl]
  373. // CHECK:STDERR: let U:! Z;
  374. // CHECK:STDERR: ^
  375. // CHECK:STDERR: fail_todo_reference_same_constant_in_different_self.carbon:[[@LINE-7]]:1: note: interface is currently being defined [InterfaceIncompleteWithinDefinition]
  376. // CHECK:STDERR: interface Z {
  377. // CHECK:STDERR: ^~~~~~~~~~~~~
  378. // CHECK:STDERR:
  379. let U:! Z;
  380. }
  381. // TODO: Should not be diagnosed as a cycle, once the incorrect failure above is
  382. // fixed.
  383. fn F(A:! Z where .T = (), B:! Z where .T = .U.T and .U = A) {}
  384. // --- fail_todo_non_cycle_with_self_reference.carbon
  385. library "[[@TEST_NAME]]";
  386. interface Z {
  387. // TODO: This should not be an error.
  388. //
  389. // CHECK:STDERR: fail_todo_non_cycle_with_self_reference.carbon:[[@LINE+7]]:11: error: associated constant has incomplete type `Z` [IncompleteTypeInAssociatedConstantDecl]
  390. // CHECK:STDERR: let T:! Z;
  391. // CHECK:STDERR: ^
  392. // CHECK:STDERR: fail_todo_non_cycle_with_self_reference.carbon:[[@LINE-6]]:1: note: interface is currently being defined [InterfaceIncompleteWithinDefinition]
  393. // CHECK:STDERR: interface Z {
  394. // CHECK:STDERR: ^~~~~~~~~~~~~
  395. // CHECK:STDERR:
  396. let T:! Z;
  397. let U:! type;
  398. // TODO: This should not be an error.
  399. //
  400. // CHECK:STDERR: fail_todo_non_cycle_with_self_reference.carbon:[[@LINE+7]]:11: error: associated constant has incomplete type `Z` [IncompleteTypeInAssociatedConstantDecl]
  401. // CHECK:STDERR: let V:! Z;
  402. // CHECK:STDERR: ^
  403. // CHECK:STDERR: fail_todo_non_cycle_with_self_reference.carbon:[[@LINE-17]]:1: note: interface is currently being defined [InterfaceIncompleteWithinDefinition]
  404. // CHECK:STDERR: interface Z {
  405. // CHECK:STDERR: ^~~~~~~~~~~~~
  406. // CHECK:STDERR:
  407. let V:! Z;
  408. }
  409. // TODO: Should not be diagnosed as a cycle, once the incorrect failure above is
  410. // fixed.
  411. fn F(A:! Z where .T = .V.U and .V = .Self and .U = ()) -> A.T {
  412. return ();
  413. }
  414. // --- fail_cycle_with_unrelated_associated_constant.carbon
  415. library "[[@TEST_NAME]]";
  416. interface Z {
  417. let T0:! type;
  418. let T1:! type;
  419. let T2:! type;
  420. let T3:! type;
  421. }
  422. // CHECK:STDERR: fail_cycle_with_unrelated_associated_constant.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(Z.T0)` [FacetTypeConstraintCycle]
  423. // CHECK:STDERR: fn F(T:! Z where .T0 = .T1 and .T1 = .T0 and .T2 = .T3) {}
  424. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  425. // CHECK:STDERR:
  426. fn F(T:! Z where .T0 = .T1 and .T1 = .T0 and .T2 = .T3) {}
  427. // --- fail_cycle_with_branching_in_rhs.carbon
  428. library "[[@TEST_NAME]]";
  429. interface Z {
  430. let T0:! type;
  431. let T1:! type;
  432. let T2:! type;
  433. let T3:! type;
  434. let T4:! type;
  435. }
  436. // TODO: There should only be one diagnostic here.
  437. //
  438. // CHECK:STDERR: fail_cycle_with_branching_in_rhs.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(Z.T1)` [FacetTypeConstraintCycle]
  439. // CHECK:STDERR: fn F(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T3 = .T1) {}
  440. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  441. // CHECK:STDERR:
  442. fn F(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T3 = .T1) {}
  443. // CHECK:STDERR: fail_cycle_with_branching_in_rhs.carbon:[[@LINE+4]]:10: error: found cycle in facet type constraint for `.(Z.T0)` [FacetTypeConstraintCycle]
  444. // CHECK:STDERR: fn G(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T3 = .T0) {}
  445. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  446. // CHECK:STDERR:
  447. fn G(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T3 = .T0) {}
  448. // --- no_cycle_with_branching_in_rhs.carbon
  449. library "[[@TEST_NAME]]";
  450. interface Z {
  451. let T0:! type;
  452. let T1:! type;
  453. let T2:! type;
  454. let T3:! type;
  455. let T4:! type;
  456. let T5:! type;
  457. }
  458. // These create misdiagnostics if the resolving algorithms messes up tracking
  459. // its stack during replacements by leaving either of .T2 or .T3 on the stack
  460. // (from the RHS of .T1) while resolving the other. Or it can fail to apply the
  461. // () up the chain correctly.
  462. fn F(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T4 = () and .T3 = .T2) -> T.T0 {
  463. return ((), ());
  464. }
  465. fn G(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T4 = .T5 and .T5 = () and .T3 = .T2) -> T.T0 {
  466. return ((), ());
  467. }
  468. fn H(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = (.T4, ()) and .T3 = .T2 and .T4 = {}) -> T.T0 {
  469. return (({}, ()), ({}, ()));
  470. }
  471. fn I(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T3 = .T2 and .T4 = ()) -> T.T0 {
  472. return ((), ());
  473. }
  474. fn J(T:! Z where .T0 = .T1 and .T1 = (.T2, .T3) and .T2 = .T4 and .T4 = .T5 and .T3 = .T2 and .T5 = ()) -> T.T0 {
  475. return ((), ());
  476. }
  477. // --- indirection_through_self_rhs.carbon
  478. library "[[@TEST_NAME]]";
  479. interface I {
  480. let I1:! type;
  481. let I2:! type;
  482. }
  483. interface J {
  484. let J1:! I;
  485. }
  486. // The value of .I1 is (), but to know that requires resolving .J1 first then
  487. // .J1.I2.
  488. fn F(T:! I & J where .J1 = .Self and .I1 = .J1.I2 and .I2 = ()) -> T.I1 {
  489. return ();
  490. }
  491. // --- indirection_through_not_self_rhs.carbon
  492. library "[[@TEST_NAME]]";
  493. interface I {
  494. let I1:! type;
  495. let I2:! type;
  496. }
  497. interface J {
  498. let J1:! I;
  499. }
  500. // The value of .I1 is (), but to know that requires resolving .J1 first then
  501. // .J1.I2.
  502. fn F(U:! I where .I2 = (), T:! I & J where .J1 = U and .I1 = .J1.I2) -> T.I1 {
  503. return ();
  504. }
  505. // --- indirection_through_unresolved_access_rhs.carbon
  506. library "[[@TEST_NAME]]";
  507. interface I {
  508. let I1:! type;
  509. let I2:! type;
  510. }
  511. interface J {
  512. let J1:! I;
  513. }
  514. // If we assume the nested `.J1` access will resolve to a facet value, we may
  515. // loop forever trying to resolve the `.I2` access. We should gracefully accept
  516. // that it does not resolve further.
  517. fn F(T:! I & J where .I1 = .J1.I2) {}
  518. // CHECK:STDOUT: --- fail_cycle.carbon
  519. // CHECK:STDOUT:
  520. // CHECK:STDOUT: constants {
  521. // CHECK:STDOUT: %M.type: type = facet_type <@M> [concrete]
  522. // CHECK:STDOUT: %M.assoc_type: type = assoc_entity_type @M [concrete]
  523. // CHECK:STDOUT: %assoc0: %M.assoc_type = assoc_entity element0, @M.%X [concrete]
  524. // CHECK:STDOUT: %assoc1: %M.assoc_type = assoc_entity element1, @M.%Y [concrete]
  525. // CHECK:STDOUT: %assoc2: %M.assoc_type = assoc_entity element2, @M.%Z [concrete]
  526. // CHECK:STDOUT: %.Self: %M.type = bind_symbolic_name .Self [symbolic_self]
  527. // CHECK:STDOUT: %.Self.as_type: type = facet_access_type %.Self [symbolic_self]
  528. // CHECK:STDOUT: %M.lookup_impl_witness: <witness> = lookup_impl_witness %.Self, @M [symbolic_self]
  529. // CHECK:STDOUT: %impl.elem0: type = impl_witness_access %M.lookup_impl_witness, element0 [symbolic_self]
  530. // CHECK:STDOUT: %impl.elem1: type = impl_witness_access %M.lookup_impl_witness, element1 [symbolic_self]
  531. // CHECK:STDOUT: %impl.elem2: type = impl_witness_access %M.lookup_impl_witness, element2 [symbolic_self]
  532. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  533. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  534. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  535. // CHECK:STDOUT: }
  536. // CHECK:STDOUT:
  537. // CHECK:STDOUT: imports {
  538. // CHECK:STDOUT: }
  539. // CHECK:STDOUT:
  540. // CHECK:STDOUT: file {
  541. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  542. // CHECK:STDOUT: %T.patt: <error> = symbolic_binding_pattern T, 0 [concrete]
  543. // CHECK:STDOUT: } {
  544. // CHECK:STDOUT: %.loc13_12.1: type = splice_block %.loc13_12.2 [concrete = <error>] {
  545. // CHECK:STDOUT: %M.ref: type = name_ref M, file.%M.decl [concrete = constants.%M.type]
  546. // CHECK:STDOUT: <elided>
  547. // CHECK:STDOUT: %.Self.ref.loc13_18: %M.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  548. // CHECK:STDOUT: %X.ref.loc13_18: %M.assoc_type = name_ref X, @X.%assoc0 [concrete = constants.%assoc0]
  549. // CHECK:STDOUT: %.Self.as_type.loc13_18: type = facet_access_type %.Self.ref.loc13_18 [symbolic_self = constants.%.Self.as_type]
  550. // CHECK:STDOUT: %.loc13_18: type = converted %.Self.ref.loc13_18, %.Self.as_type.loc13_18 [symbolic_self = constants.%.Self.as_type]
  551. // CHECK:STDOUT: %impl.elem0.loc13_18: type = impl_witness_access constants.%M.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  552. // CHECK:STDOUT: %.Self.ref.loc13_23: %M.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  553. // CHECK:STDOUT: %Y.ref.loc13_23: %M.assoc_type = name_ref Y, @Y.%assoc1 [concrete = constants.%assoc1]
  554. // CHECK:STDOUT: %.Self.as_type.loc13_23: type = facet_access_type %.Self.ref.loc13_23 [symbolic_self = constants.%.Self.as_type]
  555. // CHECK:STDOUT: %.loc13_23: type = converted %.Self.ref.loc13_23, %.Self.as_type.loc13_23 [symbolic_self = constants.%.Self.as_type]
  556. // CHECK:STDOUT: %impl.elem1.loc13_23: type = impl_witness_access constants.%M.lookup_impl_witness, element1 [symbolic_self = constants.%impl.elem1]
  557. // CHECK:STDOUT: %.Self.ref.loc13_30: %M.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  558. // CHECK:STDOUT: %Y.ref.loc13_30: %M.assoc_type = name_ref Y, @Y.%assoc1 [concrete = constants.%assoc1]
  559. // CHECK:STDOUT: %.Self.as_type.loc13_30: type = facet_access_type %.Self.ref.loc13_30 [symbolic_self = constants.%.Self.as_type]
  560. // CHECK:STDOUT: %.loc13_30: type = converted %.Self.ref.loc13_30, %.Self.as_type.loc13_30 [symbolic_self = constants.%.Self.as_type]
  561. // CHECK:STDOUT: %impl.elem1.loc13_30: type = impl_witness_access constants.%M.lookup_impl_witness, element1 [symbolic_self = constants.%impl.elem1]
  562. // CHECK:STDOUT: %.Self.ref.loc13_35: %M.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  563. // CHECK:STDOUT: %X.ref.loc13_35: %M.assoc_type = name_ref X, @X.%assoc0 [concrete = constants.%assoc0]
  564. // CHECK:STDOUT: %.Self.as_type.loc13_35: type = facet_access_type %.Self.ref.loc13_35 [symbolic_self = constants.%.Self.as_type]
  565. // CHECK:STDOUT: %.loc13_35: type = converted %.Self.ref.loc13_35, %.Self.as_type.loc13_35 [symbolic_self = constants.%.Self.as_type]
  566. // CHECK:STDOUT: %impl.elem0.loc13_35: type = impl_witness_access constants.%M.lookup_impl_witness, element0 [symbolic_self = constants.%impl.elem0]
  567. // CHECK:STDOUT: %.Self.ref.loc13_42: %M.type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  568. // CHECK:STDOUT: %Z.ref: %M.assoc_type = name_ref Z, @Z.%assoc2 [concrete = constants.%assoc2]
  569. // CHECK:STDOUT: %.Self.as_type.loc13_42: type = facet_access_type %.Self.ref.loc13_42 [symbolic_self = constants.%.Self.as_type]
  570. // CHECK:STDOUT: %.loc13_42: type = converted %.Self.ref.loc13_42, %.Self.as_type.loc13_42 [symbolic_self = constants.%.Self.as_type]
  571. // CHECK:STDOUT: %impl.elem2: type = impl_witness_access constants.%M.lookup_impl_witness, element2 [symbolic_self = constants.%impl.elem2]
  572. // CHECK:STDOUT: %.loc13_48.1: %empty_tuple.type = tuple_literal ()
  573. // CHECK:STDOUT: %.loc13_48.2: type = converted %.loc13_48.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  574. // CHECK:STDOUT: %.loc13_12.2: type = where_expr %.Self [concrete = <error>] {
  575. // CHECK:STDOUT: requirement_rewrite %impl.elem0.loc13_18, %impl.elem1.loc13_23
  576. // CHECK:STDOUT: requirement_rewrite %impl.elem1.loc13_30, %impl.elem0.loc13_35
  577. // CHECK:STDOUT: requirement_rewrite %impl.elem2, %.loc13_48.2
  578. // CHECK:STDOUT: }
  579. // CHECK:STDOUT: }
  580. // CHECK:STDOUT: %T: <error> = bind_symbolic_name T, 0 [concrete = <error>]
  581. // CHECK:STDOUT: }
  582. // CHECK:STDOUT: }
  583. // CHECK:STDOUT:
  584. // CHECK:STDOUT: generic fn @F(%T: <error>) {
  585. // CHECK:STDOUT: !definition:
  586. // CHECK:STDOUT:
  587. // CHECK:STDOUT: fn() {
  588. // CHECK:STDOUT: !entry:
  589. // CHECK:STDOUT: return
  590. // CHECK:STDOUT: }
  591. // CHECK:STDOUT: }
  592. // CHECK:STDOUT:
  593. // CHECK:STDOUT: specific @F(<error>) {}
  594. // CHECK:STDOUT: