base_constructor.carbon 625 B

12345678910111213141516171819202122232425262728293031
  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 extends A {
  17. fn Create() -> Self {
  18. return {.base = A.Create(), .value_b = 2};
  19. }
  20. var value_b: i32;
  21. }
  22. fn Main() -> i32 {
  23. var b: B = B.Create();
  24. Print("{0}", b.value_a);
  25. Print("{0}", b.value_b);
  26. return 0;
  27. }