dot_self_is_other.carbon 827 B

1234567891011121314151617181920212223242526272829
  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: 12
  9. package ExplorerTest api;
  10. interface A { fn F() -> i32; }
  11. interface B { fn F() -> i32; }
  12. impl i32 as A { fn F() -> i32 { return 1; } }
  13. impl i32 as B { fn F() -> i32 { return 2; } }
  14. fn GetA[T:! A](x: T) -> i32 { return x.F(); }
  15. fn GetAB[T:! B where .Self is A](x: T) -> i32 {
  16. // Note that there's no ambiguity in the use of the name F here.
  17. // `x.F` is `x.(B.F)` because the constraint only treats `B`, not
  18. // `A`, as a lookup context.
  19. return 10 * GetA(x) + x.F();
  20. }
  21. fn Main() -> i32 {
  22. var v: i32 = 0;
  23. return GetAB(v);
  24. }