base_constructor.carbon 636 B

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