3116bbbb3bae537a09e62f5c8331a431d6c56b1e 851 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: Allocate B
  7. // CHECK:STDOUT: DESTRUCTOR B
  8. // CHECK:STDOUT: DESTRUCTOR A
  9. // CHECK:STDOUT: Delete B
  10. // CHECK:STDOUT: DESTRUCTOR B
  11. // CHECK:STDOUT: DESTRUCTOR A
  12. // CHECK:STDOUT: Return
  13. // CHECK:STDOUT: result: 0
  14. package ExplorerTest;
  15. base class A{
  16. destructor[self: Self] {
  17. Print("DESTRUCTOR A");
  18. }
  19. }
  20. class B {
  21. extend base: A;
  22. fn Create() -> Self{
  23. return {.base={}};
  24. }
  25. destructor[self: Self] {
  26. Print("DESTRUCTOR B");
  27. }
  28. }
  29. fn Main() -> i32 {
  30. Print("Allocate B");
  31. var pb: B* = heap.New(B.Create());
  32. Print("Delete B");
  33. heap.Delete(pb);
  34. Print("Return");
  35. return 0;
  36. }