mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 06:05:17 +00:00
Fixes bug where null default allows 0 as a value.
This commit is contained in:
@@ -1975,7 +1975,8 @@ class TsGenerator : public BaseGenerator {
|
||||
GenDocComment(code_ptr);
|
||||
code += "static " + namer_.Method("add", field);
|
||||
code += "(builder:flatbuffers.Builder, " + argname + ":" +
|
||||
GetArgType(imports, struct_def, field, false) + ") {\n";
|
||||
GetArgType(imports, struct_def, field, /* allow null */ true) +
|
||||
") {\n";
|
||||
code += " builder.addField" + GenWriteMethod(field.value.type) + "(";
|
||||
code += NumToString(it - struct_def.fields.vec.begin()) + ", ";
|
||||
if (field.value.type.base_type == BASE_TYPE_BOOL) { code += "+"; }
|
||||
@@ -1983,11 +1984,7 @@ class TsGenerator : public BaseGenerator {
|
||||
if (!IsScalar(field.value.type.base_type)) {
|
||||
code += "0";
|
||||
} else if (HasNullDefault(field)) {
|
||||
if (IsLong(field.value.type.base_type)) {
|
||||
code += "BigInt(0)";
|
||||
} else {
|
||||
code += "0";
|
||||
}
|
||||
code += "null";
|
||||
} else {
|
||||
if (field.value.type.base_type == BASE_TYPE_BOOL) { code += "+"; }
|
||||
code += GenDefaultValue(field, imports);
|
||||
|
||||
Reference in New Issue
Block a user