flow9 icon indicating copy to clipboard operation
flow9 copied to clipboard

How to prevent definitions leaks from imports? (namespace is currently global)

Open mationai opened this issue 5 years ago • 1 comments

defined a function called sum.

Compiler errors on "Duplicate name 'sum'" if I import fs/filesystem;

No error if not importing fs/filesystem;

2 issues here.

  1. How to avoid importing everything in fs/filesystem when I want to import only selected ones?

  2. Worst, seems like sum was leaked from fs/filesystem due to it importing: math/md5 -> math/bits -> math/math where sum was defined.

mationai avatar May 03 '19 20:05 mationai

Flow has a global namespace at the moment, so there is no way to avoid that. From the FAQ:

Why is there a global name space?

Yeah, this sucks, but it is hard to fix. It requires changing not only the compiler and all the backends, but also the debugger, the profiler and other similar tools. We originally thought that we would have to fix this quickly to be able to work many people together, but after many years of working with flow, it turns out not to be as bad. Of course, it is annoying, and we want to fix it, but at the same time, in practice, there are also what we can call collateral benefits. The most important is that any top-level name is unambiguous which helps communication and avoid mistakes. However, it might be something we will try to tackle.

alstrup avatar May 04 '19 03:05 alstrup