3246530de7e46a174acd24fd87d38695fd5e36c9 929 B

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