www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - alias to fully qualified symbol gives error, but when module is also a

reply Dennis <dkorpel gmail.com> writes:
I was trying to rename an imported `sqrt` (wrongly), but I 
stumbled upon this weird behavior:
```
void main() {
     import core.stdc.math: sqrtf, sqrt;
     alias sqrtd = core.stdc.math.sqrt;
     auto a = sqrtd(1);
}
```
onlineapp.d(3): Error: undefined identifier core.stdc.math.sqrt

However, when std.stdio is imported:

```
void main() {
     import std.stdio;
     import core.stdc.math: sqrtf, sqrt;
     alias sqrtd = core.stdc.math.sqrt;
     auto a = sqrtd(1);
}
```
onlineapp.d(4): Deprecation: std.stdio.core is not visible from 
module onlineapp
onlineapp.d(4): Deprecation: std.stdio.core is not visible from 
module onlineapp

Apart from the deprecation, it actually works. What is the 
intended behavior here? Is this a new issue, or does the 
deprecation already cover it once it becomes an error?

(Btw the correct way to do this is `import core.stdc.math: sqrtf, 
sqrtd = sqrt;`)
May 05 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 5 May 2019 at 15:22:31 UTC, Dennis wrote:
 I was trying to rename an imported `sqrt` (wrongly), but I 
 stumbled upon this weird behavior:
 ```
 void main() {
     import core.stdc.math: sqrtf, sqrt;
     alias sqrtd = core.stdc.math.sqrt;
     auto a = sqrtd(1);
 }
 ```
 onlineapp.d(3): Error: undefined identifier core.stdc.math.sqrt
You didn't actually import the name `core` there, only the specific symbols `sqrtf` and `sqrt`, which are now considered direct children of your scope. So it doesn't know where to begin with that fully qualified name - it doesn't know what `core` is. So this is working as designed by the module and name lookup rules. The std.stdio one is supposed to be an error; the old buggy behavior was to bypass the private import in these cases and that is why it is deprecated pending changes.
May 05 2019
parent Dennis <dkorpel gmail.com> writes:
On Sunday, 5 May 2019 at 18:07:10 UTC, Adam D. Ruppe wrote:
 The std.stdio one is supposed to be an error; the old buggy 
 behavior was to bypass the private import in these cases and 
 that is why it is deprecated pending changes.
Thanks, that answers my question. The old private-bypassing behavior is apparently more broken than I thought.
May 05 2019