vibe.d
vibe.d copied to clipboard
Can't serialize to session struct with enum member
I have a struct with enum like this:
struct UserModel // : BasicModel
{
int id;
string fullname;
string email;
// ...
enum systemId = 1;
}
Then I try to put it to session:
struct Registrator
{
import vibe.http.server;
// ...
enum LoggedUserVar = "loggedUser";
enum LoggedVar = "logged";
// ...
bool login(UserModel user)
{
session.set(LoggedUserVar, user); // <--- problem is here
session.set(LoggedVar, true);
return true;
}
// ...
}
Expected: compilation without errors In fact:
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/internal/meta/traits.d(243,25): Error: argument 1 has no protection
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/internal/meta/traits.d(159,19): Error: template instance vibe.internal.meta.traits.isPublicMember!(UserModel, "systemId") error instantiating
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/internal/meta/traits.d(134,14): instantiated from here: isRWField!(UserModel, "systemId")
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d(1141,14): instantiated from here: isRWPlainField!(UserModel, "systemId")
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d(1136,4): instantiated from here: FilterSerializableFields!(UserModel, DefaultPolicy, "systemId")
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/data/serialization.d(1137,4): ... (11 instantiations, -v to show) ...
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/session.d(92,35): instantiated from here: serialize!(UserModel)
source/vcm/bll/registrator.d(29,14): instantiated from here: set!(UserModel)
enum systemId = 1;
definitely is not struct field to set, so expected behavior is ignoring this symbol in (de)serialization process.
Workaround for current moment:
// enum systemId = 1;
@property static uint systemId()
{
return 1;
}
For which compiler version does this happen and in which scope is the UserModel
struct defined? I tried to make a reproduction case, but that worked without errors.
DMD64 D Compiler v2.071.1
UserModel defined in separate module vcm.bll.model.user and imported using import vcm.bll.model.user;
Moving UserModel to the registrator module doesn't affect error.
upd: Updated to v2.073.0, no change
@crimaniak : Is this bug still present ? I can't seem to reproduce either. If it is, could you make a simple, self-contained test case ?
It will be hard. I abandon D years ago because of a big amount of bugs, but I will try to find an example.