www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Forbidden file names?

reply Brian <bcallah openbsd.org> writes:
Hello --

Apologies if this is answered somewhere in the documentation.
I was trying out the sample code on the dlang.org home page.

When I got to the "Sort an Array at Compile-Time" example, I 
saved it on my machine as sort.d. When I tried to build sort.d, 
the compile failed. But when I renamed sort.d to anything else 
(e.g., array.d), the compilation was fine.

I am wondering if this is expected.

Thanks! Terminal output below explaining the above.

~Brian

/home/brian/d $ cat sort.d
void main()
{
     import std.algorithm, std.conv, std.stdio;

     "Starting program".writeln;

     // Sort a constant declaration at Compile-Time
     enum a = [ 3, 1, 2, 4, 0 ];
     static immutable b = sort(a);

     // Print the result _during_ compilation
     pragma(msg, text("Finished compilation: ", b));
}
/home/brian/d $ dmd sort.d
sort.d(9): Error: function expected before `()`, not `module 
sort` of type `void`
sort.d(12):        while evaluating `pragma(msg, text(T...)(T 
args) if (T.length > 0)("Finished compilation: ", b))`
/home/brian/d $ mv sort.d array.d
/home/brian/d $ dmd array.d
Finished compilation: immutable(SortedRange!(int[], "a < b", 
SortedRangeOptions.assumeSorted))([0, 1, 2, 3, 4])
Mar 14 2021
parent reply Paul Backus <snarwin gmail.com> writes:
On Sunday, 14 March 2021 at 20:47:00 UTC, Brian wrote:
 Hello --

 Apologies if this is answered somewhere in the documentation.
 I was trying out the sample code on the dlang.org home page.

 When I got to the "Sort an Array at Compile-Time" example, I 
 saved it on my machine as sort.d. When I tried to build sort.d, 
 the compile failed. But when I renamed sort.d to anything else 
 (e.g., array.d), the compilation was fine.
[...]
 /home/brian/d $ dmd sort.d
 sort.d(9): Error: function expected before `()`, not `module 
 sort` of type `void`
This is the error you get when you try to call a function that has the same name as the current module. The best way to fix it is to rename the module, but if you can't, you can use an alias to disambiguate: alias sort = std.algorithm.sort;
Mar 14 2021
parent Brian <bcallah openbsd.org> writes:
On Sunday, 14 March 2021 at 20:57:39 UTC, Paul Backus wrote:
 This is the error you get when you try to call a function that 
 has the same name as the current module. The best way to fix it 
 is to rename the module, but if you can't, you can use an alias 
 to disambiguate:

     alias sort = std.algorithm.sort;
Thanks.
Mar 14 2021