dot_self_is_other.carbon 776 B

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