destroy_base_class.carbon 740 B

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