Commit f84f4fcb authored by Eric Myhre's avatar Eric Myhre

fix gen'd struct field lookups to keep ptrness.

Before this diff, when getting a field back out, if it was nullable or
optional, you'd get one more level of pointer than you started with.
Oddly, this still compiled.  Tests sensibly rejected it, though.
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent 61bf5b5d
......@@ -62,6 +62,9 @@ func TestStructBuilder(t *testing.T) {
Wish(t, err, ShouldEqual, nil)
Wish(t, n.ReprKind(), ShouldEqual, ipld.ReprKind_Map)
Wish(t, plz(n.LookupString("f1")), ShouldEqual, plz(String__NodeBuilder{}.CreateString("a")))
Wish(t, plz(n.LookupString("f2")), ShouldEqual, plz(String__NodeBuilder{}.CreateString("b")))
Wish(t, plz(n.LookupString("f3")), ShouldEqual, plz(String__NodeBuilder{}.CreateString("c")))
Wish(t, plz(n.LookupString("f4")), ShouldEqual, plz(String__NodeBuilder{}.CreateString("d")))
})
})
}
......
......@@ -79,7 +79,11 @@ func (gk generateKindStruct) EmitNodeMethodLookupString(w io.Writer) {
return ipld.Null, nil
}
{{- end}}
{{- if or $field.IsOptional $field.IsNullable }}
return *x.{{ $field.Name }}, nil
{{- else}}
return x.{{ $field.Name }}, nil
{{- end}}
{{- end}}
default:
return nil, typed.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment