mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00

* Fix issue 20369 - shadowed variable in foreach loop always considered "foreach variable" * Remove unintuitive phrase in deprecation message * Fix deprecation message in test * Add original variable's line information in deprecation (error) message
35 lines
644 B
D
35 lines
644 B
D
// https://issues.dlang.org/show_bug.cgi?id=2195
|
|
// REQUIRED_ARGS: -de
|
|
/*
|
|
TEST_OUTPUT:
|
|
---
|
|
fail_compilation/fail2195.d(17): Deprecation: variable `variable` is shadowing variable `fail2195.main.variable`
|
|
fail_compilation/fail2195.d(14): declared here
|
|
---
|
|
*/
|
|
|
|
void main()
|
|
{
|
|
int[int] arr;
|
|
int variable;
|
|
foreach (i, j; arr)
|
|
{
|
|
int variable; // shadowing is disallowed but not detected
|
|
}
|
|
}
|
|
|
|
void fun()
|
|
{
|
|
int var1, var2, var3;
|
|
|
|
void gun()
|
|
{
|
|
int var1; // OK?
|
|
|
|
int[] arr;
|
|
foreach (i, var2; arr) {} // OK?
|
|
|
|
int[int] aa;
|
|
foreach (k, var3; aa) {} // Not OK??
|
|
}
|
|
}
|