mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Explorer: fix variables not cleaned up if declared before unformed (#2544)
Fix variables not being properly cleaned up if declared before an unformed variable.
### Details
Currently the following example / test
```
package ExplorerTest api;
class A {
var i: i32;
destructor[self: Self] {
Print("Destructor A {0}", self.i);
}
}
fn Main() -> i32 {
var a0: A;
var a1: A = {.i = 1};
var a2: A;
var a3: A = {.i = 3};
return 0;
}
```
prints
```
Destructor A 3
```
instead of
```
Destructor A 3
Destructor A 1
```
This PR fixes the issue in the `CleanUp` logic.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// RUN: %{explorer-run}
|
||||
// RUN: %{explorer-run-trace}
|
||||
// CHECK:STDOUT: Destructor A 3
|
||||
// CHECK:STDOUT: Destructor A 1
|
||||
// CHECK:STDOUT: result: 0
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
class A {
|
||||
var i: i32;
|
||||
destructor[self: Self] {
|
||||
Print("Destructor A {0}", self.i);
|
||||
}
|
||||
}
|
||||
|
||||
fn Main() -> i32 {
|
||||
var a0: A;
|
||||
var a1: A = {.i = 1};
|
||||
var a2: A;
|
||||
var a3: A = {.i = 3};
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user