Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum values are not generated correctly when the first value is discarded #86

Closed
smola opened this issue Jun 13, 2017 · 7 comments
Closed
Labels

Comments

@smola
Copy link

smola commented Jun 13, 2017

It seems that if you define an enum using _ = iota, the values in Go will start at 1, while the generated proto will start at 0.

I couldn't really verify this yet.
This is where I'm seeing divergences:
https://github.com/bblfsh/sdk/blob/master/uast/uast.go
https://github.com/bblfsh/sdk/blob/master/uast/generated.proto
(Roles enum)

@erizocosmico
Copy link
Contributor

As a workaround, you can do Foo = 1 + iota instead of using _ = iota.

@smola
Copy link
Author

smola commented Jun 15, 2017

@erizocosmico 👍 thanks!

@erizocosmico
Copy link
Contributor

erizocosmico commented Jun 15, 2017

@smola on a second thought, we can't do anything to solve that on the proteus side. Protobuf enums must start at 0 (https://developers.google.com/protocol-buffers/docs/proto3#enum) If you want the enums to match you'll have to start at 0.

Talk to @Serabe tomorrow IRL.

@erizocosmico
Copy link
Contributor

erizocosmico commented Jun 26, 2017

@smola one thing you could do is naming the invalid value, instead of using _:

type Role uint64

const (
  Invalid Role = iota

  Foo
  Bar
  ...
)

It's done extensively in the stdlib, so I don't think is a completely bad solution (example: https://golang.org/src/go/ast/scope.go?s=3516:3532#L127).

The drawback of this would be that INVALID would be generated in the proto as well.

If that is not an OK solution for you guys, we'd have to look into options for respecting the mapping, but we can't promise there will be a solution for this, since enum values must start with 0 no matter what.

@erizocosmico
Copy link
Contributor

Ping @smola

1 similar comment
@Serabe
Copy link
Contributor

Serabe commented Jul 5, 2017

Ping @smola

@abeaumont
Copy link

looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants