value_expr_from_reference_subobject.carbon 897 B

123456789101112131415161718192021222324252627282930313233343536373839
  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: 0: Heap{}, 1: C{.d = D{}}
  7. // CHECK:STDOUT: Initialize d from reference expression from subobject
  8. // CHECK:STDOUT: 0: Heap{}, 1: C{.d = D{}}
  9. // CHECK:STDOUT: c destroyed
  10. // CHECK:STDOUT: d destroyed
  11. // CHECK:STDOUT: result: 0
  12. package ExplorerTest api;
  13. class D {
  14. destructor[self: Self] {
  15. Print("d destroyed");
  16. }
  17. }
  18. class C {
  19. destructor[self: Self] {
  20. Print("c destroyed");
  21. }
  22. var d: D;
  23. }
  24. fn FromReferenceExpressionDeref() {
  25. var c_var: C = {.d = {}};
  26. heap.PrintAllocs();
  27. Print("Initialize d from reference expression from subobject");
  28. let d: D = c_var.d;
  29. heap.PrintAllocs();
  30. }
  31. fn Main() -> i32 {
  32. FromReferenceExpressionDeref();
  33. return 0;
  34. }