Pathological import symbol shadowing

Timon Gehr timon.gehr at
Sun Nov 15 14:24:21 UTC 2020

On 15.11.20 10:06, Walter Bright wrote:
> On 11/13/2020 2:57 PM, H. S. Teoh wrote:
>> Just ran into this today:
>>     void main() {
>>         int[string] aa;
>>         int x;
>>         x = aa.get("abc", 123);    // OK
>>         import std;
>>         x = aa.get("abc", 123);    // Error: template 
>> cannot deduce function from argument types ...
>>         import std, object;
>>         x = aa.get("abc", 123);    // OK
>>     }
> Using:
>      import std;
> is a bad idea.

Straw man. Seeing that we're at it: It's also a strange idea to write a 
program that does not perform any I/O. Also, obviously the AA is 
overkill, we could just assign 123 to x, which the snippet does three 
times in a row, but x is never read again!

Writing that code is a bad idea; just use void main(){} instead, it will 
do what you wanted, and without any compilation errors. :o)

I think it's safe to say that the snippet was written to illustrate a 
point and to focus on anything else to the detriment of a discussion of 
that point is just deflection.

If the language was working properly, the code would compile and run 
fine. There is a hole in the design of the language here. There's no 
need to prioritize this particular issue, but I don't understand why you 
don't just acknowledge that this is not how the compiler should behave 
in this situation.

It's not just rejects-valid either, this issue has accepts-invalid cases:

import std.stdio;

string readAndLog(string filename){
     import std.file;
     auto text=readText(filename);
     write(filename," read successfully!\n");
     return text;

void main(){

More information about the Digitalmars-d mailing list