FreeFem / FreeFem-sources

FreeFEM source code
https://freefem.org/
Other
796 stars 193 forks source link

Function ambiguity #98

Closed Stack-OverFlo closed 5 years ago

Stack-OverFlo commented 5 years ago

Describe the bug Function ambiguity

Expected behavior Should not compile

Code

func real[int] test (real[int] &u) {
    return u;
}

func real[int] test (real[int] &u) {
    return u;
}

real[int] u = [1, 2, 3];
//real[int] v = test(u);

LinearCG(test, u);

Desktop (please complete the following information):

frederichecht commented 5 years ago

Never compile the 2 fonctions test have the same prototype => bug no way to choose.

sgarnotel commented 5 years ago

This code really compiles, and leads to a seg fault

prj- commented 5 years ago

The segfault is trivial to fix. Getting a function ambiguity message is tougher.

sgarnotel commented 5 years ago

When we use the commented line, we correctly have a function ambiguity message, but when used in LinearCG (probably with other functions), this leads to a silent segfault.

Did users really have the right to write two functions with the same prototype ? (in edp file)

prj- commented 5 years ago

You have the message because, as Frédéric said, the function is being evaluated in the .edp. In the .cpp, there is a missing ffassert there https://github.com/FreeFem/FreeFem-sources/blob/master/src/fflib/lgfem.cpp#L585 (and probably in many other places).

frederichecht commented 5 years ago

a put a correction 10 : //real[int] v = test(u); 11 : 12 : LinearCG(test, u) Warning ambiguity Polymorphic Find 2 ( <3KN_IdE> : ) ( <3KN_IdE> : ) We have ambiguity 2 current line = 12 Assertion fail : (A)