class_inheritance_function_call.carbon 862 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. // 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 extends C {
  19. fn FunctionD(var i: i32) {
  20. C.FunctionC(i);
  21. Print("Class D, call {0}", i);
  22. }
  23. }
  24. fn Main() -> i32 {
  25. // Calling function from class type
  26. D.FunctionD(0);
  27. // Note: D.FunctionC(0); is not accessible
  28. // Calling function from class object
  29. var d: D = {.base={}};
  30. d.FunctionC(1);
  31. d.FunctionD(2);
  32. return 0;
  33. }