dot_self_is_other.carbon 1020 B

12345678910111213141516171819202122232425262728293031
  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. // RUN: %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. // CHECK: result: 12
  11. package ExplorerTest api;
  12. interface A { fn F() -> i32; }
  13. interface B { fn F() -> i32; }
  14. impl i32 as A { fn F() -> i32 { return 1; } }
  15. impl i32 as B { fn F() -> i32 { return 2; } }
  16. fn GetA[T:! A](x: T) -> i32 { return x.F(); }
  17. fn GetAB[T:! B where .Self is A](x: T) -> i32 {
  18. // Note that there's no ambiguity in the use of the name F here.
  19. // `x.F` is `x.(B.F)` because the constraint only treats `B`, not
  20. // `A`, as a lookup context.
  21. return 10 * GetA(x) + x.F();
  22. }
  23. fn Main() -> i32 {
  24. var v: i32 = 0;
  25. return GetAB(v);
  26. }