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

Optional Enum generates code that doesn't compile #562

Closed
anopheles opened this issue Jan 20, 2022 · 1 comment
Closed

Optional Enum generates code that doesn't compile #562

anopheles opened this issue Jan 20, 2022 · 1 comment

Comments

@anopheles
Copy link

anopheles commented Jan 20, 2022

See this proto definiton as an example

syntax = "proto3";

option go_package = "example.com";
package examplepb;

import "validate/validate.proto";

message Person {
  oneof optional_status {
   Status status = 1 [(validate.rules).enum = {not_in: [0]}] ;
  }

  optional Status additional_status = 2 [(validate.rules).enum = {not_in: [1]}] ;
}

enum Status {
  STATUS_UNKNOWN = 0;
  STATUS_ACTIVATED = 1;
  STATUS_DEACTIVATED = 2;
}

The generated code looks like this

var _Person_Status_NotInLookup = map[*Status]struct{}{
	0: {},
}

As Status is a pointer we receive following error message:

0' (type untyped int) cannot be represented by the type *Status

Thanks for all the great work!

These are the header values of my pb.go

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.27.1
// 	protoc        v3.19.3
// source: example.proto
@anopheles
Copy link
Author

FYI: The problem still exists with v0.6.4.

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

No branches or pull requests

2 participants