babygo icon indicating copy to clipboard operation
babygo copied to clipboard

Support Defer statement with a method call

Open DQNEO opened this issue 1 year ago • 0 comments

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()

DQNEO avatar Aug 31 '23 11:08 DQNEO