Bug 18038 – Error: with symbol is shadowing local symbol
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-12-06T11:48:09Z
Last change time
2017-12-06T12:03:36Z
Assigned to
No Owner
Creator
JR
Comments
Comment #0 by zorael — 2017-12-06T11:48:09Z
Arch/Manjaro 64-bit, dmd 2.077.0
struct Thing
{
import std.string : indexOf;
}
void main()
{
import std.stdio : writeln;
import std.string : indexOf;
Thing thing;
with (thing)
{
writeln(typeof(indexOf).stringof);
}
}
source/app.d(14,24): Error: with symbol app.Thing.indexOf is shadowing local symbol indexOf
https://run.dlang.io/is/voz7wb
Comment #1 by simen.kjaras — 2017-12-06T12:03:36Z
This is intended behavior.
https://dlang.org/spec/statement.html#WithStatement:
5. Use of with object symbols that shadow local symbols with the same identifier are not allowed. This is to reduce the risk of inadvertant breakage of with statements when new members are added to the object declaration.
struct S
{
float x;
}
void main()
{
int x;
S s;
with (s)
{
x++; // error, shadows the int x declaration
}
}