Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some implicit array casts are missing #17650

Open
dlangBugzillaToGithub opened this issue Apr 4, 2014 · 2 comments
Open

Some implicit array casts are missing #17650

dlangBugzillaToGithub opened this issue Apr 4, 2014 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

Denis Shelomovskii (@denis-sh) reported this on 2014-04-04T06:37:07Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=12519

Description

This code should compile:
---
void main()
{
    void[] va;
    byte[] ba;
    byte[1] sba;
    const byte[] cba;
    const byte[1] csba;
    va ~= ba; // ok
    va ~= sba; // ok
    va ~= cba; // Error: cannot append type const(byte[]) to type void[]
    va ~= csba; // Error: cannot append type const(byte[1]) to type void[]
}
---
@dlangBugzillaToGithub
Copy link
Author

k.hara.pg commented on 2014-05-26T08:06:34Z

void[] is an array of untyped *mutable* data. So appending const data to mutable array will violate type system.

@dlangBugzillaToGithub
Copy link
Author

verylonglogin.reg commented on 2014-05-26T13:23:47Z

(In reply to Kenji Hara from comment #1)
> void[] is an array of untyped *mutable* data. So appending const data to
> mutable array will violate type system.

But `byte` has no indirections so `const byte` is convertible to `byte` and this logically equivalent code is valid:
---
void main()
{
    void[] va;
    const byte[] cba;
    const byte[1] csba;
    byte[] tmp;
    tmp ~= cba;
    tmp ~= csba;
    va = tmp;
}
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant