destroy_inner_destructor.carbon 836 B

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