Bug 18432 – alias x = x where x is an imported symbol should result in an error
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-02-13T09:05:11Z
Last change time
2018-03-27T08:09:40Z
Assigned to
No Owner
Creator
RazvanN
Comments
Comment #0 by razvan.nitu1305 — 2018-02-13T09:05:11Z
import std.stdio : writeln;
alias writeln = writeln;
This code should result in an error. On the other hand:
import std.stdio : writeln;
alias writeln = std.stio.writeln;
should compile (and it does momentarily)
Comment #1 by razvan.nitu1305 — 2018-02-13T11:22:58Z
Actually,
import std.stdio : writeln;
alias writeln = std.stdio.writeln;
Does not compile successfully, it issues an error : "Undefined identifier std.stdio.writeln".
Comment #2 by schveiguy — 2018-02-15T18:43:48Z
(In reply to RazvanN from comment #1)
> Actually,
>
> import std.stdio : writeln;
> alias writeln = std.stdio.writeln;
>
> Does not compile successfully, it issues an error : "Undefined identifier
> std.stdio.writeln".
This one works (or rather fails) as expected. Importing using selective imports does not pull in the fully qualified name to the namespace.
I'm not 100% sure on the first one, as it seems like if it works, it's simply a no-op. Can you give a reason why having it succeed is bad?
Comment #3 by razvan.nitu1305 — 2018-02-21T07:01:57Z
*** Issue 18480 has been marked as a duplicate of this issue. ***
Comment #4 by razvan.nitu1305 — 2018-02-21T07:05:56Z
(In reply to Steven Schveighoffer from comment #2)
> I'm not 100% sure on the first one, as it seems like if it works, it's
> simply a no-op. Can you give a reason why having it succeed is bad?
It's not a no-op but actually created some weird alias behind the scenes, sth. like writeln (declared alias) -> writeln (alias from selective import) -> std.stdio.writeln (real symbol), not too sure.
But with Raszvan's recent protection fix for selective imports this started to ran into an infinite loop.
Comment #6 by slavo5150 — 2018-02-21T08:23:38Z
Something that might be contributing to the problem is the compiler currently allows selectively importing private aliases:
--- moduleA.d
module moduleA;
private int i;
private alias I = i;
static this()
{
i = 10;
}
--- main.d
import std.stdio;
import moduleA : I;
void main()
{
writeln(I);
}
That compiles and prints "10". The statement `import moduleA : I;` should fail because `I` is private.