[Issue 19126] Compiler removes inout on templated parameter and then complains it's not there

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 3 13:20:35 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19126

--- Comment #10 from Ali Ak <ali.akhtarzada at gmail.com> ---
Ahhh this inout just hurts my head. So is fixing inout on return a much bigger
bug than the more simple "don't remove inout from a parameter if the return
value has inout"?

Currently you can do this and then things behave consistently. Fixes this
problem but does't solve the "allowing inout on return" problem.

auto wrap0(T)(inout(T) t) {
    static if (is(T == immutable)) {
        return immutable W!T();
    } else {
        return inout W!T();
    }
}

When T is an immutable it seems like the compiler should be doing this by
itself. If it decides to "replace" inout(immutable) with just immutable, then
it should replace inout everywhere with immutable. SO why doesn't
inout(W!(immutable int)) become immutable(T!int)? That would also make this
error go away right?

Maybe the compiler shouldn't be reducing inout in the first place? It is
supposed to be (IIUC) qualifiers in => qualifiers out right? So why does it
remove it before the it "lands" somewhere? This makes no sense regardless of
immutable being the strongest qualifier. The purposes of inout and immutable
seem orthogonal. It's not a mutability qualifier, it's a "transport of
mutability information" qualifier right?

--


More information about the Digitalmars-d-bugs mailing list