destroy_inner_destructor.carbon 782 B

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