named_constant.carbon 6.7 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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.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/named_constant.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/named_constant.carbon
  12. // --- fail_todo_named_constant_in_rewrite.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {
  15. let X:! type;
  16. let Y:! type;
  17. }
  18. fn Test() {
  19. let Constant:! type = ();
  20. fn F(T:! I where .X = Constant) {}
  21. fn G(T:! I where .X = Constant) {
  22. // TODO: The facet type T in G should match the facet type T in F.
  23. // CHECK:STDERR: fail_todo_named_constant_in_rewrite.carbon:[[@LINE+7]]:5: error: cannot deduce value for generic parameter `Constant` [DeductionIncomplete]
  24. // CHECK:STDERR: F(T);
  25. // CHECK:STDERR: ^~~~
  26. // CHECK:STDERR: fail_todo_named_constant_in_rewrite.carbon:[[@LINE-7]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
  27. // CHECK:STDERR: fn F(T:! I where .X = Constant) {}
  28. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. F(T);
  31. }
  32. }
  33. // --- fail_todo_named_constant_two_levels_in_rewrite.carbon
  34. library "[[@TEST_NAME]]";
  35. interface I {
  36. let X:! type;
  37. let Y:! type;
  38. }
  39. fn Test() {
  40. let Constant2:! type = ();
  41. let Constant:! type = (Constant2, );
  42. fn F(T:! I where .X = Constant) {}
  43. fn G(T:! I where .X = Constant) {
  44. // TODO: The facet type T in G should match the facet type T in F.
  45. // CHECK:STDERR: fail_todo_named_constant_two_levels_in_rewrite.carbon:[[@LINE+7]]:5: error: cannot deduce value for generic parameter `Constant2` [DeductionIncomplete]
  46. // CHECK:STDERR: F(T);
  47. // CHECK:STDERR: ^~~~
  48. // CHECK:STDERR: fail_todo_named_constant_two_levels_in_rewrite.carbon:[[@LINE-7]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
  49. // CHECK:STDERR: fn F(T:! I where .X = Constant) {}
  50. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. // CHECK:STDERR:
  52. F(T);
  53. }
  54. }
  55. // --- fail_todo_named_constant_in_rewrite_callee.carbon
  56. library "[[@TEST_NAME]]";
  57. interface I {
  58. let X:! type;
  59. let Y:! type;
  60. }
  61. fn Test() {
  62. let Constant:! type = ();
  63. fn F(T:! I where .X = Constant) {}
  64. fn G(T:! I where .X = ()) {
  65. // TODO: The facet type T in G should match the facet type T in F.
  66. // CHECK:STDERR: fail_todo_named_constant_in_rewrite_callee.carbon:[[@LINE+7]]:5: error: cannot deduce value for generic parameter `Constant` [DeductionIncomplete]
  67. // CHECK:STDERR: F(T);
  68. // CHECK:STDERR: ^~~~
  69. // CHECK:STDERR: fail_todo_named_constant_in_rewrite_callee.carbon:[[@LINE-7]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
  70. // CHECK:STDERR: fn F(T:! I where .X = Constant) {}
  71. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. // CHECK:STDERR:
  73. F(T);
  74. }
  75. }
  76. // --- fail_todo_named_constant_in_rewrite_caller.carbon
  77. library "[[@TEST_NAME]]";
  78. interface I {
  79. let X:! type;
  80. let Y:! type;
  81. }
  82. fn Test() {
  83. let Constant:! type = ();
  84. fn F(T:! I where .X = ()) {}
  85. fn G(T:! I where .X = Constant) {
  86. // TODO: The facet type T in G should match the facet type T in F.
  87. // CHECK:STDERR: fail_todo_named_constant_in_rewrite_caller.carbon:[[@LINE+7]]:5: error: cannot convert type `T` that implements `I where .(I.X) = Constant` into type implementing `I where .(I.X) = ()` [ConversionFailureFacetToFacet]
  88. // CHECK:STDERR: F(T);
  89. // CHECK:STDERR: ^~~~
  90. // CHECK:STDERR: fail_todo_named_constant_in_rewrite_caller.carbon:[[@LINE-7]]:8: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  91. // CHECK:STDERR: fn F(T:! I where .X = ()) {}
  92. // CHECK:STDERR: ^
  93. // CHECK:STDERR:
  94. F(T);
  95. }
  96. }
  97. // --- fail_todo_named_constant_in_nested_facet_type.carbon
  98. library "[[@TEST_NAME]]";
  99. interface I {
  100. let X:! type;
  101. let Y:! type;
  102. }
  103. fn Test() {
  104. let Constant:! type = ();
  105. // TODO: The .Self reference in each .X should be different, there should be
  106. // no cycle here.
  107. // CHECK:STDERR: fail_todo_named_constant_in_nested_facet_type.carbon:[[@LINE+4]]:12: error: found cycle in facet type constraint for `.(I.X)` [FacetTypeConstraintCycle]
  108. // CHECK:STDERR: fn F(T:! I where .X = (I where .X = Constant)) {}
  109. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. // CHECK:STDERR:
  111. fn F(T:! I where .X = (I where .X = Constant)) {}
  112. // CHECK:STDERR: fail_todo_named_constant_in_nested_facet_type.carbon:[[@LINE+4]]:12: error: found cycle in facet type constraint for `.(I.X)` [FacetTypeConstraintCycle]
  113. // CHECK:STDERR: fn G(T:! I where .X = (I where .X = Constant)) {
  114. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. // CHECK:STDERR:
  116. fn G(T:! I where .X = (I where .X = Constant)) {
  117. // TODO: The facet type T in G should match the facet type T in F.
  118. F(T);
  119. }
  120. }
  121. // --- fail_todo_named_constant_in_nested_facet_type_caller.carbon
  122. library "[[@TEST_NAME]]";
  123. interface I {
  124. let X:! type;
  125. let Y:! type;
  126. }
  127. fn Test() {
  128. let Constant:! type = ();
  129. fn F(T:! I where .X = (I where .X = ())) {}
  130. // TODO: The .Self reference in each .X should be different, there should be
  131. // no cycle here.
  132. // CHECK:STDERR: fail_todo_named_constant_in_nested_facet_type_caller.carbon:[[@LINE+4]]:12: error: found cycle in facet type constraint for `.(I.X)` [FacetTypeConstraintCycle]
  133. // CHECK:STDERR: fn G(T:! I where .X = (I where .X = Constant)) {
  134. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. // CHECK:STDERR:
  136. fn G(T:! I where .X = (I where .X = Constant)) {
  137. // TODO: The facet type T in G should match the facet type T in F.
  138. F(T);
  139. }
  140. }
  141. // --- fail_named_constant_in_nested_facet_type_callee.carbon
  142. library "[[@TEST_NAME]]";
  143. interface I {
  144. let X:! type;
  145. let Y:! type;
  146. }
  147. fn Test() {
  148. let Constant:! type = ();
  149. // TODO: The .Self reference in each .X should be different, there should be
  150. // no cycle here.
  151. // CHECK:STDERR: fail_named_constant_in_nested_facet_type_callee.carbon:[[@LINE+4]]:12: error: found cycle in facet type constraint for `.(I.X)` [FacetTypeConstraintCycle]
  152. // CHECK:STDERR: fn F(T:! I where .X = (I where .X = Constant)) {}
  153. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. // CHECK:STDERR:
  155. fn F(T:! I where .X = (I where .X = Constant)) {}
  156. fn G(T:! I where .X = (I where .X = ())) {
  157. // TODO: The facet type T in G should match the facet type T in F.
  158. F(T);
  159. }
  160. }