https://issues.dlang.org/show_bug.cgi?id=20149
--- Comment #3 from Mike Franklin <slavo5...@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 --