dot_self_is_other.carbon 779 B

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