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