extends.carbon 772 B

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