ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
313 stars 43 forks source link

Fix single variable assignment in deeper scopes #74

Closed ameliatastic closed 1 year ago

ameliatastic commented 1 year ago

Explanation here.

Closes #73

ameliatastic commented 1 year ago

(Note that I know this isn't done yet, this will cause errors when a variable is re-assigned in the same scope. PR is here so that more eyes can get on this.)

mcintyre94 commented 1 year ago

Good to see the CI picking up these changes! Would it be worth adding an example that does a bit more scope stuff - maybe including lists and also tuples like you were talking about on the issue?

ameliatastic commented 1 year ago

Yeah, absolutely. I'll quote you in the stability thread so that I don't forget.

ameliatastic commented 1 year ago

Looks better now!

Here's the relevant generated code from Miguel's sample:

    let mut myboolean = true;
    let mut newnumber = 1f64;
    let mut mylist = Mutable::new(vec![3f64]);

    if number > 0f64 {
        myboolean = false;

        newnumber = 10f64;

        index_assign!(mylist.borrow_mut(), mylist.wrapped_index(0), 4f64);

Assignments are happening the right spots again.