BlackEdder / painlessjson

D library for converting any custom types to and from JSON the painless way.
Boost Software License 1.0
24 stars 3 forks source link

Adding a to, but not from @property function results in compile error #9

Closed BlackEdder closed 9 years ago

BlackEdder commented 9 years ago

Adding the following to struct PointPrivateProperty

@property double z()
{ 
   return 1.0;
}

Results in the following compile error

Building painlessjson 0.7.0+commit.26.g77f0017 configuration "__test__library__", build type unittest.
Compiling using dmd...
source/painlessjson/painlessjson.d-mixin-317(317): Error: function painlessjson.unittesttypes.PointPrivateProperty.z () is not callable using argument types (double)
source/painlessjson/painlessjson.d(403): Error: template instance painlessjson.painlessjson.fromJSON!(PointPrivateProperty) error instantiating
FAIL .dub/build/__test__library__-unittest-linux.posix-x86_64-dmd_2066-ADD9549AACDE6684EA1B2A25675717A2/ __test__library__ executable
Error executing command test: dmd failed with exit code 1.
BlackEdder commented 9 years ago

Probably need special isWritableFieldOrProperty that can be used here: https://github.com/BlackEdder/painlessjson/blob/master/source/painlessjson/painlessjson.d#L312

BlackEdder commented 9 years ago

Tried to solve this in the writable property branch, by checking the arity (number of variables) of the @property function, but getMember only retrieves the first defined function of a name. This results in a compile error given the unittest at the end of traits.d. If the definition of the foo functions is reversed this does pass. Do you know how to do this @Zalastax ?

Zalastax commented 9 years ago

I'll investigate this today. Great catch!

BlackEdder commented 9 years ago

I have fixed it by checking with getOverloads (see last commit in writable_property branch). There is some code duplication going on though and whenever I try to move code around I run into CTFE issues. My CTFE foo is not very strong (and I have no more time today), so I would appreciate if you could have a quick look at cleaning it up :)

After that I think we can release it as version 1.0.0

Zalastax commented 9 years ago

I didn't have to use any complicated CTFE, just a better compiles traits usage. I think the code in my pull request is a good solution for this issue.

Zalastax commented 9 years ago

This issue is ready to be closed. I wouldn't mind having write permission just to manage issues. I will keep using pull requests for code.

BlackEdder commented 9 years ago

I added you as collaborator. Probably best if we both work through pull requests and the other can quickly review it.