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