require_constrains_self.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/require_constrains_self.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/require_constrains_self.carbon
  12. // --- fail_self_doesnt_meet_constraint.carbon
  13. library "[[@TEST_NAME]]";
  14. interface Y2 {}
  15. interface Y(T:! Y2) {}
  16. // TODO: The error should be that Self does not implement Y2, not that it can't
  17. // be identified. We should allow identifying `Self`.
  18. //
  19. // CHECK:STDERR: fail_self_doesnt_meet_constraint.carbon:[[@LINE+17]]:37: error: facet type of value `Self` can not be identified [ImplLookupInUnidentifiedFacetTypeOfQuerySelf]
  20. // CHECK:STDERR: constraint W { extend require impls Y(Self); }
  21. // CHECK:STDERR: ^~~~~~~
  22. // CHECK:STDERR: fail_self_doesnt_meet_constraint.carbon:[[@LINE+14]]:1: note: constraint is currently being defined [NamedConstraintIncompleteWithinDefinition]
  23. // CHECK:STDERR: constraint W { extend require impls Y(Self); }
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~
  25. // CHECK:STDERR: fail_self_doesnt_meet_constraint.carbon:[[@LINE-10]]:13: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  26. // CHECK:STDERR: interface Y(T:! Y2) {}
  27. // CHECK:STDERR: ^
  28. // CHECK:STDERR:
  29. // CHECK:STDERR: fail_self_doesnt_meet_constraint.carbon:[[@LINE+7]]:37: error: cannot convert type `Self` that implements `W` into type implementing `Y2` [ConversionFailureFacetToFacet]
  30. // CHECK:STDERR: constraint W { extend require impls Y(Self); }
  31. // CHECK:STDERR: ^~~~~~~
  32. // CHECK:STDERR: fail_self_doesnt_meet_constraint.carbon:[[@LINE-17]]:13: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  33. // CHECK:STDERR: interface Y(T:! Y2) {}
  34. // CHECK:STDERR: ^
  35. // CHECK:STDERR:
  36. constraint W { extend require impls Y(Self); }
  37. // --- fail_todo_self_meets_constraint.carbon
  38. library "[[@TEST_NAME]]";
  39. interface Y2 {}
  40. interface Y(T:! Y2) {}
  41. constraint W {
  42. // TODO: This should allow the next line to work, as Self should be known to impl Y2.
  43. require impls Y2;
  44. // CHECK:STDERR: fail_todo_self_meets_constraint.carbon:[[@LINE+17]]:24: error: facet type of value `Self` can not be identified [ImplLookupInUnidentifiedFacetTypeOfQuerySelf]
  45. // CHECK:STDERR: extend require impls Y(Self);
  46. // CHECK:STDERR: ^~~~~~~
  47. // CHECK:STDERR: fail_todo_self_meets_constraint.carbon:[[@LINE-6]]:1: note: constraint is currently being defined [NamedConstraintIncompleteWithinDefinition]
  48. // CHECK:STDERR: constraint W {
  49. // CHECK:STDERR: ^~~~~~~~~~~~~~
  50. // CHECK:STDERR: fail_todo_self_meets_constraint.carbon:[[@LINE-10]]:13: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  51. // CHECK:STDERR: interface Y(T:! Y2) {}
  52. // CHECK:STDERR: ^
  53. // CHECK:STDERR:
  54. // CHECK:STDERR: fail_todo_self_meets_constraint.carbon:[[@LINE+7]]:24: error: cannot convert type `Self` that implements `W` into type implementing `Y2` [ConversionFailureFacetToFacet]
  55. // CHECK:STDERR: extend require impls Y(Self);
  56. // CHECK:STDERR: ^~~~~~~
  57. // CHECK:STDERR: fail_todo_self_meets_constraint.carbon:[[@LINE-17]]:13: note: initializing generic parameter `T` declared here [InitializingGenericParam]
  58. // CHECK:STDERR: interface Y(T:! Y2) {}
  59. // CHECK:STDERR: ^
  60. // CHECK:STDERR:
  61. extend require impls Y(Self);
  62. }