mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-14 16:36:55 +00:00
Fix handling of +/-inf defaults in TS/rust/go/dart codegen (#7588)
+/-inf were not being handled, and so invalid typescript was being generated when a float/double had an infinite default value. NaN was being handled correctly. Co-authored-by: Derek Bailey <derekbailey@google.com> Co-authored-by: Casper <casperneo@uchicago.edu>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
// independent from idl_parser, since this code is not needed for most clients
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
#include "flatbuffers/code_generators.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
@@ -721,16 +722,17 @@ class DartGenerator : public BaseGenerator {
|
||||
if (!value.constant.empty() && value.constant != "0") {
|
||||
if (IsBool(value.type.base_type)) {
|
||||
return "true";
|
||||
} else if (value.constant == "nan" || value.constant == "+nan" ||
|
||||
value.constant == "-nan") {
|
||||
return "double.nan";
|
||||
} else if (value.constant == "inf" || value.constant == "+inf") {
|
||||
return "double.infinity";
|
||||
} else if (value.constant == "-inf") {
|
||||
return "double.negativeInfinity";
|
||||
} else {
|
||||
return value.constant;
|
||||
}
|
||||
if (IsScalar(value.type.base_type)) {
|
||||
if (StringIsFlatbufferNan(value.constant)) {
|
||||
return "double.nan";
|
||||
} else if (StringIsFlatbufferPositiveInfinity(value.constant)) {
|
||||
return "double.infinity";
|
||||
} else if (StringIsFlatbufferNegativeInfinity(value.constant)) {
|
||||
return "double.negativeInfinity";
|
||||
}
|
||||
}
|
||||
return value.constant;
|
||||
} else if (IsBool(value.type.base_type)) {
|
||||
return "false";
|
||||
} else if (IsScalar(value.type.base_type) && !IsUnion(value.type)) {
|
||||
|
||||
Reference in New Issue
Block a user