【修复】修复生成的go代码读取可空变量的bug

main
walon 2022-03-14 11:10:48 +08:00
parent dee9bcdfe0
commit ced29f9fca
1 changed files with 1 additions and 1 deletions

View File

@ -12,7 +12,7 @@ namespace Luban.Job.Cfg.TypeVisitors
if (type.IsNullable) if (type.IsNullable)
{ {
var jsonObjName = $"__json_{fieldName}__"; var jsonObjName = $"__json_{fieldName}__";
return $"{{ var _ok_ bool; var {jsonObjName} interface{{}}; if {jsonObjName}, _ok_ = {bufName}[\"{fieldName}\"]; !_ok_ || {jsonObjName} == nil {{ return }} else {{ var __x__ {type.Apply(GoTypeUnderingNameVisitor.Ins)}; {type.Apply(GoDeserializeJsonUndering2Visitor.Ins, "__x__", jsonObjName)}; {varName} = {(type.Apply(GoIsPointerTypeVisitor.Ins) ? "&" : "")}__x__ }}}}"; return $"{{ var _ok_ bool; var {jsonObjName} interface{{}}; if {jsonObjName}, _ok_ = {bufName}[\"{fieldName}\"]; !_ok_ || {jsonObjName} == nil {{ {varName} = nil }} else {{ var __x__ {type.Apply(GoTypeUnderingNameVisitor.Ins)}; {type.Apply(GoDeserializeJsonUndering2Visitor.Ins, "__x__", jsonObjName)}; {varName} = {(type.Apply(GoIsPointerTypeVisitor.Ins) ? "&" : "")}__x__ }}}}";
} }
else else
{ {