value_expr_from_reference_subobject.carbon 898 B

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