qualified_constraint_member.carbon 631 B

123456789101112131415161718192021222324252627282930
  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 Foo api;
  7. interface A {
  8. fn F[self: Self]() -> i32;
  9. }
  10. interface B {
  11. fn G(o: Self) -> i32;
  12. }
  13. alias C = A & B;
  14. class X {
  15. extend impl as A {
  16. fn F[self: Self]() -> i32 { return 10 * self.n; }
  17. }
  18. extend impl as B {
  19. fn G(o: Self) -> i32 { return o.n; }
  20. }
  21. var n: i32;
  22. }
  23. fn Main() -> i32 {
  24. var v: X = {.n = 1};
  25. var w: X = {.n = 2};
  26. return v.(C.F)() + X.(C.G)(w);
  27. }
  28. // CHECK:STDOUT: result: 12