mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
Vendored
+3
-1
@@ -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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user