From fbdeb86949021af77d81b763beca8c235212d7ce Mon Sep 17 00:00:00 2001 From: Sergey Passichenko Date: Thu, 2 May 2024 10:46:16 -0700 Subject: [PATCH] cast int literal to double if field in proto is double (#373) --- pkg/sync/golang.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/sync/golang.go b/pkg/sync/golang.go index 4f14046e..da25546a 100644 --- a/pkg/sync/golang.go +++ b/pkg/sync/golang.go @@ -638,7 +638,6 @@ func (g *goSyncer) compositeLitToProto(x *ast.CompositeLit) protoreflect.Message panic(fmt.Errorf("unsupported composite literal type %T", clTypeNode)) } default: - field.Kind() // Value is not a composite literal - try handling as a primitive value := g.primitiveToProtoValue(node) if field.Kind() == protoreflect.EnumKind { @@ -648,6 +647,11 @@ func (g *goSyncer) compositeLitToProto(x *ast.CompositeLit) protoreflect.Message msg.Set(field, protoreflect.ValueOf(protoreflect.EnumNumber(intValue))) continue } + // convert int64 to float64 (double) if this is what proto expects + // it's not 100% safe, but should be fine for values < 9007199254740993 + if intValue, ok := value.(int64); ok && field.Kind() == protoreflect.DoubleKind { + value = float64(intValue) + } msg.Set(field, protoreflect.ValueOf(value)) } }