bambam icon indicating copy to clipboard operation
bambam copied to clipboard

wrong numbering with already numbered fields

Open mark-kubacki opened this issue 10 years ago • 4 comments

bambam translates this struct…:

type Member struct {
    id             int64
    Username       string    `capid:"0"`
    UpdatedAt      time.Time `capid:"3" json:"LastUpdated"`
    Name           *string   `capid:"1" json:"DisplayName,omitempty"`
    IsAdmin        bool      `capid:"2"`
    PasswordHash   *string   `capid:"4" json:",omitempty"`
    PasswordSalt   *string   `capid:"5" json:",omitempty"`
    PrimaryGroupId *int      `capid:"6" json:",omitempty"`
    UrlToAvatar    *string   `json:",omitempty"`
}

To the following, assigning capid=3 twice:

type Member struct {
    id             int64
    Username       string    `capid:"0"`
    UpdatedAt      time.Time `capid:"3" json:"LastUpdated"`
    Name           *string   `capid:"1" json:"DisplayName,omitempty"`
    IsAdmin        bool      `capid:"2"`
    PasswordHash   *string   `capid:"4" json:",omitempty"`
    PasswordSalt   *string   `capid:"5" json:",omitempty"`
    PrimaryGroupId *int      `capid:"6" json:",omitempty"`
    UrlToAvatar    *string   `json:",omitempty" capid:"3"`
}

I have expected that it continued numbering, and assigned capid=7 to the last field.


Annotating the field with capid=7 will result in this error and no usable file output:

$ bambam -o capn.model -p model member.go
panic: problem in capid tag '' on field 'UrlToAvatar' in struct 'Member': number '7' is beyond the count of fields we have, largest available is 6
# …
    UrlToAvatar    *string   `capid:"7" json:",omitempty"`
}

Although not required in this example, the order of fields in a struct is important: If every member of a struct is comparable, then the struct becomes comparable. In that case you don't want to reorder fields to suit bambam.

mark-kubacki avatar Jul 20 '15 18:07 mark-kubacki

@wmark Thanks for reporting this. It is clearly a bug. I won't have time to take a look at this until the weekend. I'd be happy to review a fix if you'd like to prepare one.

glycerine avatar Jul 20 '15 19:07 glycerine

@wmark: sadly, I won't have time any time soon to get to this...

glycerine avatar Sep 06 '16 15:09 glycerine

Anyway, thanks for having looked into this. Perhaps someone else finds this and wants to pick it up.

mark-kubacki avatar Sep 06 '16 15:09 mark-kubacki

Oh. This is due to the lack of time.Time type support. That is, bambam doesn't claim to have time.Time support currently.

jaten-saucelabs avatar Oct 14 '16 06:10 jaten-saucelabs