destroy_inner_destructor.carbon 783 B

12345678910111213141516171819202122232425262728293031323334353637
  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 A{
  8. class B{
  9. destructor[self: Self]{
  10. Print("DESTRUCTOR B {0}",self.n);
  11. }
  12. fn Create(x: i32) -> B{
  13. return {.n = x };
  14. }
  15. var n: i32;
  16. }
  17. destructor[self: Self]{
  18. Print("DESTRUCTOR A {0}",self.n);
  19. }
  20. fn Create(x: i32) -> A{
  21. return {.n = x, .b = B.Create(2)};
  22. }
  23. var n: i32;
  24. var b : B;
  25. }
  26. fn Main() -> i32 {
  27. var a: A = A.Create(1);
  28. return 1;
  29. }
  30. // CHECK:STDOUT: DESTRUCTOR A 1
  31. // CHECK:STDOUT: DESTRUCTOR B 2
  32. // CHECK:STDOUT: result: 1