class_inheritance_methods.carbon 757 B

1234567891011121314151617181920212223242526272829303132333435363738
  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: Class 1
  9. // CHECK:STDOUT: Class 2
  10. // CHECK:STDOUT: result: 0
  11. package ExplorerTest api;
  12. base class C {
  13. fn BasePrint(v: i32) {
  14. Print("Class {0}", v);
  15. }
  16. fn Method1[self: Self]() {
  17. self.BasePrint(self.value_c);
  18. }
  19. var value_c: i32;
  20. }
  21. class D extends C {
  22. fn Method2[self: Self]() {
  23. self.BasePrint(self.value_d);
  24. }
  25. var value_d: i32;
  26. }
  27. fn Main() -> i32 {
  28. var d: D = {.base = {.value_c = 1}, .value_d = 2};
  29. d.Method1();
  30. d.Method2();
  31. return 0;
  32. }