fail_equal_indirectly.carbon 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. // RUN: %{not} %{explorer-run}
  7. // RUN: %{not} %{explorer-run-trace}
  8. package ExplorerTest api;
  9. interface Iface {
  10. let T:! type;
  11. }
  12. fn F[T:! Iface where .T == i32](x: T) {}
  13. class Class {
  14. impl as Iface where .T = i32 {}
  15. }
  16. // OK, constraint on `F` rewritten to `T:! Iface where U == i32`, which we can
  17. // prove from the constraint on `U`.
  18. fn G[U:! type where .Self == i32, T:! Iface where .T = U](x: T, y: U) {
  19. F(x);
  20. }
  21. // Not OK: would require looking through two levels of `==`.
  22. fn H[V:! type where .Self == i32, W:! Iface where .T == V](x: W, y: V) {
  23. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_equal_indirectly.carbon:[[@LINE+1]]: constraint requires that (T).(Iface.T) (with value (W).(Iface.T)) == i32, which is not known to be true
  24. F(x);
  25. }
  26. fn Main() -> i32 {
  27. var x: Class = {};
  28. G(x, 0);
  29. H(x, 0);
  30. return 0;
  31. }