base_constructor.carbon 633 B

1234567891011121314151617181920212223242526272829303132
  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: 1
  7. // CHECK:STDOUT: 2
  8. // CHECK:STDOUT: result: 0
  9. package ExplorerTest api;
  10. base class A {
  11. fn Create() -> Self {
  12. return {.value_a = 1};
  13. }
  14. var value_a: i32;
  15. }
  16. class B {
  17. extend base: A;
  18. fn Create() -> Self {
  19. return {.base = A.Create(), .value_b = 2};
  20. }
  21. var value_b: i32;
  22. }
  23. fn Main() -> i32 {
  24. var b: B = B.Create();
  25. Print("{0}", b.value_a);
  26. Print("{0}", b.value_b);
  27. return 0;
  28. }