Bug 15488 – global variable shadows function argument
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-12-31T10:50:00Z
Last change time
2017-05-11T23:52:43Z
Assigned to
nobody
Creator
or
Comments
Comment #0 by or — 2015-12-31T10:50:50Z
abc.d:
module abc;
int global_x = 0;
main.d:
void foo(int global_x) {
import std.stdio;
writefln("Address of func argument: %x", &global_x);
import abc;
writefln("Address of func argument: %x", &global_x);
}
void main() {
foo(5);
}
running:
rdmd main.d
Address of func argument: 7fff56108688
Address of func argument: 7fb0c9c04c70
If I move the import outside of 'foo' the function argument silently shadows the global variable, which seems fine to me.
Comment #1 by bugzilla — 2017-05-11T23:52:43Z
This was fixed a while ago with the changes in how symbols are looked up in imports. The example as written prints the same address for both writefln() statements.