assoc_constant_constraints_in_scope.carbon 772 B

123456789101112131415161718192021222324252627282930313233
  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: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 5
  9. package ExplorerTest api;
  10. interface A(T:! type) { let AResult:! type; }
  11. interface B(T:! type) { let BResult:! A(T); }
  12. interface I(T:! type) {
  13. let X:! B(T);
  14. // The constraints introduced by X should be in scope here.
  15. let Y:! X.BResult.AResult;
  16. }
  17. class CA {
  18. impl as A(i32) where .AResult = i32 {}
  19. }
  20. class CB {
  21. impl as B(i32) where .BResult = CA {}
  22. }
  23. class CI {
  24. impl as I(i32) where .X = CB and .Y = 5 {}
  25. }
  26. fn Main() -> i32 {
  27. var v: CI = {};
  28. return v.(I(i32).Y);
  29. }