Incorrect field order in object construction #5055

Closed
FedericoCeratto opened this Issue Nov 25, 2016 · 0 comments

Projects

None yet

2 participants

@FedericoCeratto
Contributor

When creating objects inside a sequence, the field order is not correct:

 type
  User = object of RootObj
    username, role, description, email_addr: string

let u = User(username:"user", role:"admin", description:"desc", email_addr:"email")

let us2 = @[
  User(username:"user", role:"admin", description:"desc", email_addr:"email"),
  u
]
assert us2[0].username == "user"

let us3 = @[
  u,
  User(username:"user", role:"admin", description:"desc", email_addr:"email"),
]
assert us3[0].username == "user"

let us4 = @[
  User(username:"user", role:"admin", description:"desc", email_addr:"email"),
  User(username:"user", role:"admin", description:"desc", email_addr:"email"),
]
echo us4
# prints:
# @[(username: admin, role: desc, description: email, email_addr: nil), (username: admin, role: desc, description: email, email_addr: nil)]
assert us4[0].username == "user"
@Araq Araq added the Showstopper label Nov 29, 2016
@Araq Araq added a commit that closed this issue Nov 30, 2016
@Araq Araq fixes #5055 8494338
@Araq Araq closed this in 8494338 Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment