Add addr self binding support in destructors (#3117)

Refactors `CallDestructor` and `CallFunction` to both call a new method
`BindSelfIfPresent`, which includes support for binding `addr self` if
specified. Fixes the associated unit test.

Closes #2802.
This commit is contained in:
Lucile Rose Nihlen
2023-08-29 20:46:39 +00:00
committed by GitHub
parent 82860c4573
commit af0710ea16
3 changed files with 75 additions and 55 deletions
@@ -10,7 +10,6 @@ class A {
destructor[addr self: Self*] {
self->n += 1;
Print("DESTRUCTOR A {0}", self->n);
// CHECK:STDERR: RUNTIME ERROR: fail_addr.carbon:[[@LINE+1]]: destructors currently don't support `addr self` bindings
}
var n: i32;
@@ -20,3 +19,6 @@ fn Main() -> i32 {
var a: A = {.n = 2};
return 0;
}
// CHECK:STDOUT: DESTRUCTOR A 3
// CHECK:STDOUT: result: 0
+2
View File
@@ -109,6 +109,8 @@ fn Main() -> i32 {
// CHECK:STDOUT: <[] stack-pop: ValueExpressionAction pos: 1 `{}.(interface ImplicitAs(T = class T).Convert)` results: [`bound_method<Convert>`] (phase_execution.carbon:10)
// CHECK:STDOUT: ->> step ExpressionAction pos: 1 `{}.(interface ImplicitAs(T = class T).Convert)()` results: [`bound_method<Convert>`] scope: [] (phase_execution.carbon:10) --->
// CHECK:STDOUT: -() calling function: bound_method<Convert>
// CHECK:STDOUT: === match pattern `Placeholder<self>`
// CHECK:STDOUT: from value expression with value `{}`
// CHECK:STDOUT: === match pattern `()`
// CHECK:STDOUT: from value expression with value `()`
// CHECK:STDOUT: >[] stack-push: ScopeAction pos: 0 scope: [`self: Self`: `{}`] (None)