early_rewrites.carbon 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/early_rewrites.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/early_rewrites.carbon
  12. // Tests where `ImplWitnessAccess` on the RHS of a rewrite constraint is used in
  13. // other constraints within the same facet type in ways that require the RHS to
  14. // be evaluated to a concrete value before the facet type is resolved (such as
  15. // by passing it as a parameter to a generic class).
  16. // --- nested_constraint_visible_in_type_parameter.carbon
  17. library "[[@TEST_NAME]]";
  18. interface Z {
  19. let Z1:! type;
  20. let Z2:! type;
  21. }
  22. class C(T:! Z where .Z1 = ()) {}
  23. interface J {
  24. let J1:! (Z where .Z1 = ()) where .Z2 = C(.Self);
  25. }
  26. // --- todo_earlier_constraint_visible_in_type_parameter.carbon
  27. library "[[@TEST_NAME]]";
  28. interface Z {
  29. let Z1:! type;
  30. let Z2:! type;
  31. }
  32. class C(T:! Z where .Z1 = ()) {}
  33. // TODO: Should this pass? Or do we need a `where` between .Z1 and .Z2 to make
  34. // .Z1's value visible to .Z2?
  35. // See https://github.com/carbon-language/carbon-lang/issues/5884.
  36. interface J {
  37. let J1:! Z where .Z1 = () and .Z2 = C(.Self);
  38. }
  39. // --- todo_later_constraint_visible_in_type_parameter.carbon
  40. library "[[@TEST_NAME]]";
  41. interface Z {
  42. let Z1:! type;
  43. let Z2:! type;
  44. }
  45. class C(T:! Z where .Z1 = ()) {}
  46. // TODO: Should this pass? Or do we need a `where` between .Z1 and .Z2 to make
  47. // .Z1's value visible to .Z2?
  48. // See https://github.com/carbon-language/carbon-lang/issues/5884.
  49. interface J {
  50. let J1:! Z where .Z2 = C(.Self) and .Z1 = ();
  51. }
  52. // --- fail_todo_resolved_constraint_visible_in_type_parameter.carbon
  53. library "[[@TEST_NAME]]";
  54. interface Y {
  55. let Y1:! type;
  56. }
  57. interface Z {
  58. let Z1:! Y;
  59. let Z2:! type;
  60. let Z3:! type;
  61. }
  62. interface Tuple {}
  63. impl () as Tuple {}
  64. class C(T:! Tuple) {}
  65. // TODO: Should this pass? Or do we need a `where` between .Z2 and .Z3 to make
  66. // .Z2's value visible to .Z3?
  67. // See https://github.com/carbon-language/carbon-lang/issues/5884.
  68. interface J {
  69. // CHECK:STDERR: fail_todo_resolved_constraint_visible_in_type_parameter.carbon:[[@LINE+7]]:80: error: cannot convert type `.(Z.Z2)` into type implementing `Tuple` [ConversionFailureTypeToFacet]
  70. // CHECK:STDERR: let J1:! (Z & Y where .Y1 = ()) where .Z1 = .Self and .Z2 = .Z1.Y1 and .Z3 = C(.Z2);
  71. // CHECK:STDERR: ^~~~~~
  72. // CHECK:STDERR: fail_todo_resolved_constraint_visible_in_type_parameter.carbon:[[@LINE-9]]:9: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  73. // CHECK:STDERR: class C(T:! Tuple) {}
  74. // CHECK:STDERR: ^
  75. // CHECK:STDERR:
  76. let J1:! (Z & Y where .Y1 = ()) where .Z1 = .Self and .Z2 = .Z1.Y1 and .Z3 = C(.Z2);
  77. }