babygo
babygo copied to clipboard
Support Defer statement with a method call
Currently, babygo
supports only simple function calls:
defer f()
but not method calls;
defer obj.method()
How to do it
We should capture and save the obj value on evaluating the defer statement. We can introduce an unnamed hidden variable to store it.
In other words,
This defer statement
defer obj.method()
can be transformed into something like this:
var __hidden_var__ T = obj
defer __hidden_var__.method()