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));
}
Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 14, 2021 Create alias of same name in inner scope, bug or feature? | ||||
---|---|---|---|---|
| ||||
August 14, 2021 Re: Create alias of same name in inner scope, bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tejas | On Saturday, 14 August 2021 at 03:47:05 UTC, Tejas wrote: >
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:
|
August 14, 2021 Re: Create alias of same name in inner scope, bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Saturday, 14 August 2021 at 04:01:31 UTC, Mike Parker wrote: >On Saturday, 14 August 2021 at 03:47:05 UTC, Tejas wrote: >
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:
Oh right, the Thank you very much! |
August 14, 2021 Re: Create alias of same name in inner scope, bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tejas | On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote: >[...] you can use the module name to disambiguate as well. To extend Mike answer, the general rule is that if you can distinguish two names there's no shadowing. |
August 14, 2021 Re: Create alias of same name in inner scope, bug or feature? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On Saturday, 14 August 2021 at 08:23:20 UTC, user1234 wrote: >On Saturday, 14 August 2021 at 04:09:34 UTC, Tejas wrote: >[...] you can use the module name to disambiguate as well. To extend Mike answer, the general rule is that if you can distinguish two names there's no shadowing. Understood |