buggins / ddbc

DDBC is DB Connector for D language (similar to JDBC)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pods.d should ignore functions such as opAssign

SingingBush opened this issue · comments

While working on #62 I've noticed an issue in ddbc pods.d in which the following struct was resulting in source/ddbc/pods.d-mixin-1062(1062,37): Error: generated function ddbc.ddbctest.main.User.opAssign(User p) is not callable using argument types ():

    struct User {
        long id;
        string name;
        int flags;
        Date dob;
        SysTime created;
    }

It seems that in some cases the D compiler can sometimes generate an opAssign, see documentation:

Structs with (possibly nested) postblit operator(s) will have a hidden yet elaborate compiler generated assignment operator (unless explicitly disabled).

In a similar fashion if you decide to use a class instead of a struct you can end up hitting errors if overriding a function such as toString():

    class User {
        long id;
        string name;
        int flags;
        Date dob;
        override string toString() {
            return format("{id: %s, name: %s, flags: %s, dob: %s}", id, name, flags, dob);
        }
    }

results in source/ddbc/pods.d(435,9): Error: "Member toString of class User has unsupported type string()".

I'll fix this prior to doing the SysTime changes.

I think the way to deal with this is replace the loops that do this:

foreach(m; __traits(allMembers, T)) {
    // ...
}

with this:

foreach(m; FieldNameTuple!T) {
    // ...
}

Anyone with an opinion on this please let me know asap. I'm planning on making the change fairly soon

this will get merged along with #62