eaa7bb9e4dbf3576f9587cd88b29976ca2024fe6 1012 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 A 1
  7. // CHECK:STDOUT: DESTRUCTOR A 2
  8. // CHECK:STDOUT: DESTRUCTOR A 3
  9. // CHECK:STDOUT: DESTRUCTOR A 4
  10. // CHECK:STDOUT: result: 2
  11. package ExplorerTest;
  12. class A{
  13. destructor[self: Self]{
  14. Print("DESTRUCTOR A {0}",self.n);
  15. }
  16. var n: i32;
  17. }
  18. fn ident(x: bool)-> bool{
  19. return x;
  20. }
  21. fn ident_i32(x: i32)-> i32{
  22. return x;
  23. }
  24. // It should be enforced that different runtime scopes are on the stack.
  25. //So that it can be tested that the wrong scopes are not removed from the stack.
  26. fn Main() -> i32 {
  27. var i: i32 = 0;
  28. var d: A = {.n = 4};
  29. if(ident(true)){
  30. var a: A = {.n = 3};
  31. if(true){
  32. var b: A = {.n = 2};
  33. ident_i32(2);
  34. if(ident_i32(0) == 0){
  35. var c: A = {.n = 1};
  36. return 2;
  37. }
  38. }
  39. }
  40. return 1;
  41. }