destroy_base_class.carbon 686 B

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