[Issue 6930] combined type of immutable(T) and inout(T) should be inout(const(T))

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 4 21:37:38 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6930



--- Comment #15 from Kenji Hara <k.hara.pg at gmail.com> 2011-12-04 21:37:31 PST ---
While implementing this enhancement, I've found an issue.
Following code now can compile, but introducing inout(const(T)) breaks it.

bool hasDrive(C)(in C[] path)
{
    return true;
}
inout(C)[] stripDrive(C)(inout(C)[] path)
{
    if (hasDrive(path))    // Line 7
        return path[2 .. $];
    return path;
}
void main()
{
    assert(stripDrive(`c:\`) == `\`);
}

-- error with my local patched dmd
test.d(1): Error: inout on parameter means inout must be on return type as well
(if from D1 code, replace with 'ref')
test.d(1): Error: variable test.hasDrive!(inout(char)).hasDrive.path inout
variables can only be declared inside inout functions
test.d(7): Error: template instance test.hasDrive!(inout(char)) error
instantiating
test.d(13):        instantiated from here: stripDrive!(char)
test.d(13): Error: template instance test.stripDrive!(char) error instantiating

In IFTI with hasDrive(path), C is deduced as inout(char), then a parameter
'path' is typed as 'in inout(char)', it is translated as inout(const(char)).

Give me opinions, please.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list