Type inference error in fold
When I compile the following code
module XorAddition;
import Array: {+}; // import + so we can extend it for booleans
use Array: {!=, sel};
export {+};
inline bool +(bool a, bool b) {
return a != b;
}
bool[d:shp] +(bool[d:shp] a, bool[d:shp] b) {
return {iv -> a[iv] + b[iv] };
}
and
// Play.sac
use StdIO: {print};
use Array: all except {+};
import Array: {+};
import XorAddition: {+};
int main() {
r = with {
([0] <= [iv] < [10]) : true;
}: fold(+, false);
print(r);
r = with {
([0] <= [iv] < [128]) : genarray([12,2], 1);
}: fold(+, genarray([12,2], 0));
print(r);
return 0;
}
with:
sac2c -check c XorAddition.sac
and then sac2c -check c Play.sac
It gives me:
No definition found for a function "_MAIN::+" that accepts an argument of type "bool{0}" as parameter no 1. Full argument types are "( bool{0}, bool)".
Compilation failed while Running type inference system.
make: *** [Makefile:51: Play] Fout 53
However compiling:
use StdIO: {print};
use Array: all except {+};
import Array: {+};
import XorAddition: {+};
int main() {
print(true+ true);
print(1 + 1);
print([true]+ [true]);
print([1] + [1]);
print([[true]]+ [[true]]);
print([[1]] + [[1]]);
return 0;
}
with sac2c -check c Play.sac
is fine.
When omitting -check c
this error does NOT occur.
This makes me believe that something goes wrong when inferring which + should be used in the fold and it can not find the boolean + for some reason.
If you include the code in the XorAddition module at the top of the Play.sac file and do not include the XorAddition module there are also no errors even with -check c
.