digitalmars.D.bugs - [Issue 22040] New: dip1000: foreach ref can escape scope array
- d-bugmail puremagic.com (33/33) Jun 18 2021 https://issues.dlang.org/show_bug.cgi?id=22040
https://issues.dlang.org/show_bug.cgi?id=22040 Issue ID: 22040 Summary: dip1000: foreach ref can escape scope array Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: safe, Vision Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: dkorpel live.nl This is correctly rejected: ``` ref int f(ref scope int[] arr) { foreach(ref e; arr) return e; // Error: scope variable `__r2` may not be returned assert(0); } ``` This isn't: (`scope` => `return scope`) ``` ref int f(ref return scope int[] arr) { foreach(ref e; arr) return e; assert(0); } ``` The `return` applies to the `ref arr`, not the `int[]`. This is another case of the compiler conflating `return ref` and `return scope` like in issue 21868. --
Jun 18 2021