On Wed, 25 Jan 2012 10:46:57 -0500, Era Scarecrow <rtcv...@yahoo.com> wrote:

 DMD 2.057 - Windows version

I'm in the middle of converting a medium sized project from C to D. While I'm doing that I have several static data structures. Here's where I find myself. Can't probably duplicate the error message without the full sources.

Since immutable is transitive, this should not cause an error. But I am getting this one, which repeats 4 times for all four Notepart entries:

Error: cannot implicitly convert expression ("fQuality") of type string to char[]

//for reference on types
const nLen = 4;
enum ValueType {}
struct Flags {}

alias NotePart NP;
alias ValueType VT;

struct NotePart {
        ValueType type; 
        char[] id;
        Flags flags;
        int _size;
}

struct SubRecordParts {
        char name[nLen];
        char requ[nLen];
        int size;
        NotePart[] notes;
        int identifyBy = -1;
}

//immutable should (i think) implicitly change char[] to immutable(char[])
immutable SubRecordParts subParts[] = [
        {"AADT", "", 16, [
                NP(VT.ranged_32, "IApparatus"),
                NP(VT.float_32, "fQuality"),
                NP(VT.float_32, "fWeight"),
                NP(VT.i_32, "iuses")]}
];

Your issue is here, (I'm guessing). If do this (after slimming down to a compilable sample):

alias immutable(NotePart) NP;

then it compiles.

Because the expression (guessing that you have NP aliased to NotePart) NP(...) is constructing a NotePart and not an *immutable* NotePart, it cannot resolve that part of the expression, even though the whole expression is treated as immutable after evaluation.

Maybe there's an enhancement lurking in here...

-Steve

Reply via email to