Files
carbon-lang/explorer/testdata/destructor/destroy_base_class.carbon
T
Adrien Leravat e37a69a6d5 Destroy class hierarchy when destroying class with a base (#2378)
Depends on #2361, #2421

Add support for destructors of base classes.
Features:
- Call destructors from derived to base class
- Support addressing `TupleValue` using a new `Member` variant

Changes:
- Update `StepDestroy()` to recursively call destructors from derived to base class
- Add new `Member` variant and `IndexedValue` struct to be usable with `TupleValue`
2022-12-12 09:59:03 -08:00

36 lines
740 B
Plaintext

// 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 C 3
// CHECK:STDOUT: DESTRUCTOR A 1
// CHECK:STDOUT: result: 1
package ExplorerTest api;
base class A {
destructor[self: Self]{
Print("DESTRUCTOR A {0}", self.a);
}
var a: i32;
}
base class B extends A {
var b: i32;
}
class C extends B {
destructor[self: Self]{
Print("DESTRUCTOR C {0}", self.c);
}
var c: i32;
}
fn Main() -> i32 {
var c: C = { .base={ .base={ .a=1 }, .b=2}, .c=3 };
return 1;
}