self_addr.carbon 479 B

123456789101112131415161718192021222324
  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. // NOAUTOUPDATE
  6. package ExplorerTest impl;
  7. class A {
  8. destructor[addr self: Self*] {
  9. self->n += 1;
  10. Print("DESTRUCTOR A {0}", self->n);
  11. }
  12. var n: i32;
  13. }
  14. fn Main() -> i32 {
  15. var a: A = {.n = 2};
  16. return 0;
  17. }
  18. // CHECK:STDOUT: DESTRUCTOR A 3
  19. // CHECK:STDOUT: result: 0