fail_equal_indirectly.carbon 978 B

123456789101112131415161718192021222324252627282930313233343536
  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. package ExplorerTest api;
  7. interface Iface {
  8. let T:! type;
  9. }
  10. fn F[T:! Iface where .T == i32](x: T) {}
  11. class Class {
  12. extend impl as Iface where .T = i32 {}
  13. }
  14. // OK, constraint on `F` rewritten to `T:! Iface where U == i32`, which we can
  15. // prove from the constraint on `U`.
  16. fn G[U:! type where .Self == i32, T:! Iface where .T = U](x: T, y: U) {
  17. F(x);
  18. }
  19. // Not OK: would require looking through two levels of `==`.
  20. fn H[V:! type where .Self == i32, W:! Iface where .T == V](x: W, y: V) {
  21. // CHECK:STDERR: COMPILATION ERROR: 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
  22. F(x);
  23. }
  24. fn Main() -> i32 {
  25. var x: Class = {};
  26. G(x, 0);
  27. H(x, 0);
  28. return 0;
  29. }