class_inheritance_function_call.carbon 870 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. // CHECK:STDOUT: Class C, call 0
  7. // CHECK:STDOUT: Class D, call 0
  8. // CHECK:STDOUT: Class C, call 1
  9. // CHECK:STDOUT: Class C, call 2
  10. // CHECK:STDOUT: Class D, call 2
  11. // CHECK:STDOUT: result: 0
  12. package ExplorerTest api;
  13. base class C {
  14. fn FunctionC(var i: i32) {
  15. Print("Class C, call {0}", i);
  16. }
  17. }
  18. class D {
  19. extend base: C;
  20. fn FunctionD(var i: i32) {
  21. C.FunctionC(i);
  22. Print("Class D, call {0}", i);
  23. }
  24. }
  25. fn Main() -> i32 {
  26. // Calling function from class type
  27. D.FunctionD(0);
  28. // Note: D.FunctionC(0); is not accessible
  29. // Calling function from class object
  30. var d: D = {.base={}};
  31. d.FunctionC(1);
  32. d.FunctionD(2);
  33. return 0;
  34. }