Issue 9363 - Array slice initialization with implicitly castable type
Summary: Array slice initialization with implicitly castable type
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-20 15:36 UTC by bearophile_hugs
Modified: 2024-12-01 16:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-01-20 15:36:26 UTC
This code works:

import std.typecons: Typedef;
alias Typedef!(int[]) MyArray;
void main() {
    MyArray arr;
    arr.length = 10;
    arr[] = 0;
}


While this:


import std.typecons: Typedef;
alias Typedef!(ubyte[]) MyArray;
void main() {
    MyArray arr;
    arr.length = 10;
    arr[] = 0;
}



Gives (dmd 2.062alpha):

...\dmd2\src\phobos\std\typecons.d(2811): Error: cannot implicitly convert expression (v) of type int to ubyte[]
temp.d(6): Error: template instance std.typecons.Typedef!(ubyte[], null).Typedef.Proxy!(Typedef_payload).opSliceAssign!(Typedef!(ubyte[], null), int) error instantiating
Comment 1 Andrej Mitrovic 2013-01-21 07:36:05 UTC
std.typecons.Proxy is really poorly designed. Essentially every possible operator is shoved in there without doing any sort of check on what is being wrapper (except for the one check for classes).

Btw please don't use the Platform field unless it's a platform-specific bug, thanks.
Comment 2 Andrej Mitrovic 2013-01-21 07:36:32 UTC
(In reply to comment #1)
> wrapper

I mean wrapped.
Comment 3 bearophile_hugs 2013-01-21 09:15:34 UTC
(In reply to comment #1)

> Btw please don't use the Platform field unless it's a platform-specific bug,
> thanks.

The Platform tag was set to Windows because the error message that I have put here comes from Windows. It doesn't mean it's a Windows-only problem.
Comment 4 dlangBugzillaToGithub 2024-12-01 16:16:11 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9948

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB