https://issues.dlang.org/show_bug.cgi?id=9983
--- Comment #1 from anonymous4 <dfj1es...@sneakemail.com> --- Looks like it can be solved by smart enough container constructors. See this quick PoC: --- struct Container(T) { T value; inout(T) get() inout { return value; } } /// Smart constructor auto makeContainer(T)(T arg) { alias E=typeof(cast()arg[0]); static if(is(T==inout(E)[])) { return inout(Container!(E[]))(arg); } else { return Container!T(arg); } } auto f(inout int[] a) { return makeContainer(a); } void g(immutable int[] a) { auto b=f(a); immutable Container!(int[]) c=b; immutable int[] d=c.get; immutable int[] e=b.get; //static assert(false,typeof(b).stringof); } void g(int[] a) { auto b=f(a); Container!(int[]) c=b; int[] d=c.get; int[] e=b.get; //static assert(false,typeof(b).stringof); } --- --