cppfront
cppfront copied to clipboard
[BUG] UFCS doesn't work with class/struct member variables
UFCS is not triggered when a function is called as a class method on a class member variable.
main: () -> int = {
p := std::pair(1,2);
p.first.ufcs(); // bad! compiles to p.first.ufcs() instead of CPP2_UFCS_0(ufcs, p.first)
}
The current implementation handle only member function calls syntax on one variable. Below are some examples of what works and what is not working + what changes with #18.
main: () -> int = {
i := 42;
i.ufcs(); // works
j := fun();
j.i.ufcs(); // doesn't work
fun().i.ufcs(); // doesn't work
k := fun().i;
k.ufcs(); // works
get_i(j).ufcs(); // works with https://github.com/hsutter/cppfront/pull/18
get_i(fun()).ufcs(); // works with https://github.com/hsutter/cppfront/pull/18
res := int(42).ufcs(); // works with https://github.com/hsutter/cppfront/pull/18
int(j.i).ufcs(); // works with https://github.com/hsutter/cppfront/pull/18
}
ufcs: (i:int) -> auto = {
return i+2;
}
fun: () -> (i:int) = {
i = 42;
return;
}
get_i: (r:_) -> auto = {
return r.i;
}
I know that UFCS is still a work in progress - I am reporting that to track that. I fall into that issue when working on my small project. I was returning variables using multiple return values syntax and I was trying to trigger UFCS on one of the member variables.