Thread overview
[Issue 17589] Prevent local imports from hiding imported symbols
Nov 22, 2020
Bolpat
Nov 22, 2020
timon.gehr@gmx.ch
Dec 17, 2022
Iain Buclaw
November 22, 2020
https://issues.dlang.org/show_bug.cgi?id=17589

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--- Comment #1 from Bolpat <qs.il.paperinik@gmail.com> ---
(In reply to timon.gehr from comment #0)
> Local imports should overload against less deeply nested imports. In this example, std.stdio.write and std.file.write should be treated as part of the same overload set within readAndLog. Otherwise, there is a hijacking risk.

You imported two `write` functions (overloaded sets) that weren't intended to be used next to each other. Call compiles in both sets, so by the spec [1], it's an ambiguous call. The spec does not say that "more local" imports shadow "less local" imports for functions. While [2] says that imports can shadow local definitions, [1] clearly says how overloaded sets are to be handled. At best, [1] is correct and at worst, the spec contradicts itself.

[1] https://dlang.org/spec/function.html#overload-sets
[2] https://dlang.org/spec/module.html#scoped_imports

TL;DR: It should be an ambiguity error, nothing else.

--
November 22, 2020
https://issues.dlang.org/show_bug.cgi?id=17589

--- Comment #2 from timon.gehr@gmx.ch ---
(In reply to Bolpat from comment #1)
> (In reply to timon.gehr from comment #0)
> > Local imports should overload against less deeply nested imports. In this example, std.stdio.write and std.file.write should be treated as part of the same overload set within readAndLog. Otherwise, there is a hijacking risk.
> 
> ...
> 
> TL;DR: It should be an ambiguity error, nothing else.

Yes absolutely. Reading it now, the original report was not phrased very well. std.stdio.write and std.file.write should remain in separate overload sets, but they should overload against each other so that there is an ambiguity error in this case.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=17589

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--