Avoid a type error with a non-null default value for an optional nullable string argument.

This commit is contained in:
Ms2ger 2014-03-06 22:42:26 +01:00
parent 716e1ce144
commit 54a59b9d38
3 changed files with 15 additions and 9 deletions

View file

@ -1063,13 +1063,19 @@ for (uint32_t i = 0; i < length; ++i) {
assert(type.nullable())
return handleDefault(conversionCode,
"%s.SetNull()" % varName)
return handleDefault(
conversionCode,
("static data: [u8, ..%s] = [ %s ];\n"
"%s = str::from_utf8(data).to_owned()" %
(len(defaultValue.value) + 1,
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
varName)))
value = "str::from_utf8(data).to_owned()"
if type.nullable():
value = "Some(%s)" % value
default = (
"static data: [u8, ..%s] = [ %s ];\n"
"%s = %s" %
(len(defaultValue.value) + 1,
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
varName, value))
return handleDefault(conversionCode, default)
if isMember:
# We have to make a copy, because our jsval may well not