abstract_method_base_instance.carbon 991 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. package ExplorerTest api;
  9. abstract class A {
  10. abstract fn Foo[self: Self]();
  11. }
  12. base class B {
  13. extend base: A;
  14. impl fn Foo[self: Self]() {
  15. Print("B::Foo called!");
  16. }
  17. }
  18. class C {
  19. extend base: A;
  20. impl fn Foo[self: Self]() {
  21. Print("C::Foo called!");
  22. }
  23. }
  24. abstract class D {
  25. extend base: A;
  26. }
  27. class E {
  28. extend base: D;
  29. impl fn Foo[self: Self]() {
  30. Print("E::Foo called!");
  31. }
  32. }
  33. fn Main() -> i32 {
  34. var b: B = { .base = {} };
  35. b.Foo();
  36. var c: C = { .base = {} };
  37. c.Foo();
  38. var e: E = { .base = { .base = {} } };
  39. e.Foo();
  40. return 0;
  41. }
  42. // CHECK:STDOUT: B::Foo called!
  43. // CHECK:STDOUT: C::Foo called!
  44. // CHECK:STDOUT: E::Foo called!
  45. // CHECK:STDOUT: result: 0