@@ -77,7 +77,6 @@ func init() {
77
77
// newVar if true initializes a target variable with the generated Go code
78
78
// using `:=` operator. If false, it assigns Go code to the target variable
79
79
// using `=`.
80
- //
81
80
func protoBufTransform (source , target * expr.AttributeExpr , sourceVar , targetVar string , sourceCtx , targetCtx * codegen.AttributeContext , proto , newVar bool ) (string , []* codegen.TransformFunctionData , error ) {
82
81
ta := & transformAttrs {TransformAttrs : & codegen.TransformAttrs {
83
82
SourceCtx : sourceCtx ,
@@ -387,7 +386,11 @@ func isNonZero(v interface{}) bool {
387
386
// type to target attribute of array type. It returns an error if source
388
387
// and target are not compatible for transformation.
389
388
func transformArray (source , target * expr.Array , sourceVar , targetVar string , newVar bool , ta * transformAttrs ) (string , error ) {
390
- targetRef := ta .TargetCtx .Scope .Ref (target .ElemType , ta .TargetCtx .Pkg (target .ElemType ))
389
+ elem := target .ElemType
390
+ if ta .proto {
391
+ elem = unAlias (elem )
392
+ }
393
+ targetRef := ta .TargetCtx .Scope .Ref (elem , ta .TargetCtx .Pkg (elem ))
391
394
392
395
var (
393
396
code string
@@ -415,7 +418,7 @@ func transformArray(source, target *expr.Array, sourceVar, targetVar string, new
415
418
}
416
419
417
420
src := source .ElemType
418
- tgt := target . ElemType
421
+ tgt := elem
419
422
if err = codegen .IsCompatible (src .Type , tgt .Type , "[0]" , "[0]" ); err != nil {
420
423
if ta .proto {
421
424
ta .targetInit = ta .TargetCtx .Scope .Name (tgt , ta .TargetCtx .Pkg (tgt ), ta .TargetCtx .Pointer , ta .TargetCtx .UseDefault )
@@ -693,7 +696,6 @@ func transformUnionData(source, target *expr.AttributeExpr, ta *transformAttrs)
693
696
// ta is the transform attributes
694
697
//
695
698
// seen keeps track of generated transform functions to avoid recursion
696
- //
697
699
func transformAttributeHelpers (source , target * expr.AttributeExpr , ta * transformAttrs , seen map [string ]* codegen.TransformFunctionData ) ([]* codegen.TransformFunctionData , error ) {
698
700
var (
699
701
helpers []* codegen.TransformFunctionData
@@ -952,7 +954,7 @@ func dupTransformAttrs(ta *transformAttrs) *transformAttrs {
952
954
}
953
955
954
956
const (
955
- transformGoArrayTmpl = `{{ .TargetVar }} {{ if .NewVar }}:={{ else }}={{ end }} make([]{{ .ElemTypeRef }}, len({{ .SourceVar }}))
957
+ transformGoArrayTmpl = `{{ .TargetVar }} {{ if .NewVar }}:={{ else }}={{ end }} make([]{{ .ElemTypeRef }}, len({{ .SourceVar }}))
956
958
for {{ .LoopVar }}, val := range {{ .SourceVar }} {
957
959
{{ transformAttribute .SourceElem .TargetElem "val" (printf "%s[%s]" .TargetVar .LoopVar) false .TransformAttrs -}}
958
960
}
0 commit comments