cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[FIX] Correct get_declaration_of not to skip first symbol

Open filipsajdak opened this issue 2 years ago • 1 comments

While looking for the symbol there is a loop that searches backward using normal iterators. The loop will never check symbols.cbegin() as it is excluded by i != symbols.cbegin() condition.

That makes in the below code we will never find the fun symbol

fun: (inout i : int) -> * const int = {
    return i&;
}

main: () -> int = {
    i := 42;
    p := fun(i);
    // ...
}

This change replaces normal iterators with std::reverse_iterator.

filipsajdak avatar Oct 29 '22 23:10 filipsajdak

I made small mistake that cause skipping one symbol while using std::reverse_iterator fixed in last push.

filipsajdak avatar Nov 11 '22 22:11 filipsajdak

Thanks! I applied the basic change as a separate commit to also rename the function.

hsutter avatar Dec 02 '22 23:12 hsutter

Verified on my side on my tests - works!

filipsajdak avatar Dec 03 '22 15:12 filipsajdak

I wondered why I had added a bool value. I just realized that I needed to look outside of the named function in another PR: https://github.com/hsutter/cppfront/pull/96 (I needed that to deduce the type of the symbol - it was needed to deduce if we deal with a pointer or not).

I will rebase other PRs and will see what need to be adjusted

filipsajdak avatar Dec 03 '22 16:12 filipsajdak