Taken from TDPL, the following test-case shouldn't compile: void main() { float[] arr = [1.0, 2.5, 4.0]; foreach (ref double elem; arr) { elem /= 2; } }
See also bug 3290
Should I add a wrong-code keyword to this? Floats might be implicitly convertible to double, however the foreach loop doesn't actually modify the arr array.
https://github.com/D-Programming-Language/dmd/pull/977
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4591279a8c2630d03fc5a18cd326ce19ecc4dd93 fix Issue 4510 - [tdpl] ref with a wrong type specifier is accepted https://github.com/D-Programming-Language/dmd/commit/62d6363c59362025b0c809ee865dd52d78cbf33c Merge pull request #977 from 9rnsr/fix_foreach_arg Issue 3290,4510,5435 - Add strict type check for foreach argument