Create alias of same name in inner scope, bug or feature?
Mike Parker
aldacron at gmail.com
Sat Aug 14 04:01:31 UTC 2021
On Saturday, 14 August 2021 at 03:47:05 UTC, Tejas wrote:
> ```d
> import std;
> auto abc(T)(auto ref T a, auto ref T b){
> return a+b;
> }
>
> auto def(T)(auto ref T a, auto ref T b){
> return a*b;
>
> }
> alias macro_1 = abc;
> void main()
> {
> writeln(macro_1(15, 20));
> alias macro_1 = def;// is this NOT considered variable
> shadowing?
> writeln(macro_1(100, 20));
>
> }
> ```
Shadowing local symbols is illegal. But it's okay for local
symbols to have the same name as module-scope symbols. You can
disambigbuate with [the module scope operator][1]:
```d
void main()
macro_1(); // the local symbol
.macro_1(); // the external symbol
}
```
[1]: https://dlang.org/spec/module.html#module_scope_operators
More information about the Digitalmars-d-learn
mailing list