Skip to content

Commit

Permalink
enum: fix another regression inside of oneof (#574)
Browse files Browse the repository at this point in the history
Need to use Value() to remove any pointer in the case of
an optionally present field.

Signed-off-by: Matt Klein <mklein@lyft.com>
  • Loading branch information
mattklein123 authored Mar 1, 2022
1 parent 3898097 commit 7518d9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion templates/goshared/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const enumTpl = `
{{ template "in" . }}
{{ if $r.GetDefinedOnly }}
if _, ok := {{ (typ $f).Element }}_name[int32({{ accessor . }})]; !ok {
if _, ok := {{ (typ $f).Element.Value }}_name[int32({{ accessor . }})]; !ok {
err := {{ err . "value must be one of the defined enum values" }}
if !all { return err }
errors = append(errors, err)
Expand Down
6 changes: 6 additions & 0 deletions tests/harness/cases/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ message RepeatedYetAnotherExternalEnumDefined { repeated yet_another_package.Emb

message MapEnumDefined { map<string, TestEnum> val = 1 [(validate.rules).map.values.enum.defined_only = true]; }
message MapExternalEnumDefined { map<string, other_package.Embed.Enumerated> val = 1 [(validate.rules).map.values.enum.defined_only = true]; }

message EnumInsideOneOf {
oneof foo {
TestEnum val = 1 [(validate.rules).enum.defined_only = true];
}
}

0 comments on commit 7518d9e

Please sign in to comment.