diff --git a/tools/exp/props/funcprop.go b/tools/exp/props/funcprop.go index b3b8d92..c138741 100644 --- a/tools/exp/props/funcprop.go +++ b/tools/exp/props/funcprop.go @@ -321,9 +321,7 @@ func (p *FunctionalPropertyGenerator) serializationFuncs() (*codegen.Method, *co jen.List( jen.Id("v"), jen.Err(), - ).Op(":=").Add(kind.DeserializeFn.Clone().Call().Call( - jen.Id("i"), - )), + ).Op(":=").Add(kind.deserializeFnCode(jen.Id("i"))), jen.Err().Op("!=").Nil(), ).Block( jen.Id(codegen.This()).Op(":=").Op("&").Id(p.StructName()).Values( @@ -844,7 +842,7 @@ func (p *FunctionalPropertyGenerator) addUnknownDeserializeCode(existing jen.Cod ), jen.Return( jen.Id(codegen.This()), - jen.Err(), + jen.Nil(), ), ), ) diff --git a/tools/exp/props/manager.go b/tools/exp/props/manager.go index 99f0a3f..486e93b 100644 --- a/tools/exp/props/manager.go +++ b/tools/exp/props/manager.go @@ -201,7 +201,7 @@ func (m *ManagerGenerator) createDeserializationMethod(deserName string, pubPkg, /*param=*/ nil, []jen.Code{ jen.Func().Params( - jen.Map(jen.String()).Interface(), + jen.Interface(), ).Params( jen.Qual(pubPkg.Path(), interfaceName), jen.Error(), @@ -210,7 +210,7 @@ func (m *ManagerGenerator) createDeserializationMethod(deserName string, pubPkg, []jen.Code{ jen.Return( jen.Func().Params( - jen.Id("m").Map(jen.String()).Interface(), + jen.Id("v").Interface(), ).Params( jen.Qual(pubPkg.Path(), interfaceName), jen.Error(), @@ -218,7 +218,7 @@ func (m *ManagerGenerator) createDeserializationMethod(deserName string, pubPkg, jen.List( jen.Id("i"), jen.Err(), - ).Op(":=").Qual(privPkg.Path(), deserName).Call(jen.Id("m")), + ).Op(":=").Qual(privPkg.Path(), deserName).Call(jen.Id("v")), jen.Return(jen.List( jen.Id("i"), jen.Err(), diff --git a/tools/exp/props/property.go b/tools/exp/props/property.go index 1d2bb93..d1b139b 100644 --- a/tools/exp/props/property.go +++ b/tools/exp/props/property.go @@ -96,6 +96,17 @@ func (k Kind) lessFnCode(this, other *jen.Statement) *jen.Statement { return lessCall } +func (k Kind) deserializeFnCode(this *jen.Statement) *jen.Statement { + // LessFn is not nil, this means it is a value. + if k.LessFn != nil { + return k.DeserializeFn.Clone().Call(this) + } else { + // If LessFn is nil, this means it is a type. Which requires an + // additional Call. + return k.DeserializeFn.Clone().Call().Call(this) + } +} + // PropertyGenerator is a common base struct used in both Functional and // NonFunctional ActivityStreams properties. It provides common naming patterns, // logic, and common Go code to be generated. diff --git a/tools/exp/props/type.go b/tools/exp/props/type.go index 6eb4a19..412b48c 100644 --- a/tools/exp/props/type.go +++ b/tools/exp/props/type.go @@ -645,9 +645,10 @@ func (t *TypeGenerator) kindDeserializationFunc() (deser *codegen.Function) { deser = codegen.NewCommentedFunction( t.PrivatePackage().Path(), t.deserializationFnName(), - []jen.Code{jen.Id("m").Map(jen.String()).Interface()}, + []jen.Code{jen.Id("i").Interface()}, []jen.Code{jen.Op("*").Id(t.TypeName()), jen.Error()}, []jen.Code{ + // TODO: Assertion that interface is a map. jen.Id(codegen.This()).Op(":=").Op("&").Id(t.TypeName()).Values(jen.Dict{ jen.Id(unknownMember): jen.Make(jen.Map(jen.String()).Interface()), }),