Skip to content

Commit

Permalink
feat(plc4go/tools): add nil check for stringers
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 2, 2023
1 parent 4242087 commit d343a1b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plc4go/tools/plc4xgenerator/gen.go
Expand Up @@ -236,22 +236,27 @@ func (g *Generator) generate(typeName string) {
g.Printf("\td." + field.hasLocker + ".Lock()\n")
g.Printf("\tdefer d." + field.hasLocker + ".Unlock()\n")
}
needsDereference := false
if starFieldType, ok := fieldType.(*ast.StarExpr); ok {
fieldType = starFieldType.X
needsDereference = true
}
if field.isStringer {
if needsDereference {
g.Printf("if d.%s != nil {", field.name)
}
g.Printf(stringFieldSerialize, "d."+field.name+".String()", fieldNameUntitled)
if field.hasLocker != "" {
g.Printf("\treturn nil\n")
g.Printf("}(); err != nil {\n")
g.Printf("\treturn err\n")
g.Printf("}\n")
}
if needsDereference {
g.Printf("}\n")
}
continue
}
needsDereference := false
if starFieldType, ok := fieldType.(*ast.StarExpr); ok {
fieldType = starFieldType.X
needsDereference = true
_ = needsDereference // TODO: implement
}
switch fieldType := fieldType.(type) {
case *ast.SelectorExpr:
{
Expand Down

0 comments on commit d343a1b

Please sign in to comment.