extend.carbon 719 B

1234567891011121314151617181920212223242526272829303132333435
  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. package ExplorerTest api;
  7. interface Apple(T:! type) {
  8. fn F[self: Self]() -> T;
  9. }
  10. interface Banana {
  11. extend Apple(i32);
  12. fn G[self: Self]();
  13. }
  14. class Carrot {
  15. var n: i32;
  16. }
  17. // This impl also provides an `impl Carrot as Apple(i32)`.
  18. impl Carrot as Banana {
  19. fn F[self: Self]() -> i32 { return self.n; }
  20. fn G[self: Self]() { Print("Carrot.G"); }
  21. }
  22. fn Main() -> i32 {
  23. var c: Carrot = {.n = 5};
  24. c.(Banana.G)();
  25. return c.(Apple(i32).F)();
  26. }
  27. // CHECK:STDOUT: Carrot.G
  28. // CHECK:STDOUT: result: 5