xxxxxxxxxx
import std.stdio;
:
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);
}