Thread overview | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 22, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |safe -- |
August 22, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 --- Comment #1 from Mike Franklin <slavo5150@yahoo.com> --- > Observation-2: Decorating `opSlice` with `return` causes a compiler error to be correctly emitted where the slice is escaping `foo` In the example above, that should be `fun`, not `foo`. -- |
August 22, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 --- Comment #2 from Mike Franklin <slavo5150@yahoo.com> --- Interestingly removing the `inout` attribution on `opSlice` causes the compiler to emit an error at the return statement in `fun`. I think the error should instead be emitted at the return statement of `opSlice`, but at least it doesn't compile. -- |
August 22, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 --- Comment #3 from Mike Franklin <slavo5150@yahoo.com> --- Removing all templating from the example above cause the compiler to emit what I think is correct behavior: --- import std.stdio; @safe: struct ScopeBuffer { this(char[4] buf, size_t len = 0) { this.buf = buf; this.len = len; } char[] opSlice(size_t lower, size_t upper) in { assert(lower <= len, "Lower bound must be less than or equal to the length"); assert(upper <= len, "Upper bound must be less than or equal to the length"); assert(lower <= upper, "Lower bound must be less than or equal to the upper bound"); } do { return buf[lower .. upper]; // GOOD: Compiler error here } char[4] buf; size_t len; } char[] fun() { char[4] buf = "abcd"; auto sb = ScopeBuffer(buf, 4); return sb[0..2]; } void main() { auto s = fun(); writeln(s); } --- https://run.dlang.io/is/Fo1CfP -- |
August 22, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 --- Comment #4 from Mike Franklin <slavo5150@yahoo.com> --- > Removing all templating from the example above cause the compiler to emit what I think is correct behavior: That may mean this is a duplicate of Issue 19965, but I'm not sure. -- |
August 22, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://issues.dlang.org/sh | |ow_bug.cgi?id=19965 -- |
August 23, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |accepts-invalid -- |
September 04, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 --- Comment #5 from Mike Franklin <slavo5150@yahoo.com> --- A more reduced test case: --- import std.stdio; @safe: struct ScopeBuffer { this(char[4] init) { this.buf = init; } // The bug is that `inout` implies `return` on `this`. // See https://github.com/dlang/dmd/blob/2dc5b15d1949148d460e8c809dd878e6dec8dfa3/src/dmd/func.d#L511-L513 inout(char)[] opSlice(size_t lower, size_t upper) inout do { return buf[lower .. upper]; //BUG: compiler error should be emitted here } char[4] buf; } char[] fun() { char[4] buf = "abcd"; auto sb = ScopeBuffer(buf); return sb[0..2]; } void main() { auto s = fun(); writeln(s); } --- https://run.dlang.io/is/Pu1125 The problem is that the compiler is inferring `return` on `this` when decorated with `inout`. This was discussed in issue 17927. -- |
September 04, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://issues.dlang.org/sh | |ow_bug.cgi?id=17927 -- |
September 04, 2019 [Issue 20149] [DIP1000] Local data escapes `opSlice` if not annotated with `return` | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20149 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also|https://issues.dlang.org/sh | |ow_bug.cgi?id=19965 | -- |
Copyright © 1999-2021 by the D Language Foundation