albrow / fo

An experimental language which adds functional programming features to Go.
Other
1.24k stars 34 forks source link

Generic type usage sometimes not detected in function body #14

Closed albrow closed 6 years ago

albrow commented 6 years ago

u/danredux reported this issue on Reddit:

I do find it really hard to fully understand, to some degree.

For example, why does this work:

https://play.folang.org/p/KTHZYA_290W

But this doesn't:

https://play.folang.org/p/LHiwUE97VMB

After all I only added 1 more argument to it, nothing else changed? Also, moving main() to the bottom can make it not compile, too... I must be missing something.

albrow commented 6 years ago

This is now fixed in 17970475f2847f1791a61f2bcb0c33c97e1f8674.

The issue had to do with how the Fo compiler was iterating through generic type declarations in a map. Go randomizes the order of entries an a map, and some orderings would cause Fo to miss generic usages and therefore fail to generate the required concrete types. This led to some really weird results in the Playground because it has a hard-coded random seed and the same map is always ordered the same way. So one program would always work while another would always fail, the only difference between them being how they affected the underlying random number generator (e.g., by adding entries to a map).