Skip to content

Commit

Permalink
Fix isArgument handling for zapTypeToClusterObjectType for structs. (p…
Browse files Browse the repository at this point in the history
…roject-chip#11348)

We were setting the passByReference boolean in an async function but
examining it sync in some cases, so could get the wrong answer.  The
fix is to await the async function before we examine the boolean.
  • Loading branch information
bzbarsky-apple authored and PSONALl committed Dec 2, 2021
1 parent 83cc6b0 commit 989ddca
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,41 +367,41 @@ async function zapTypeToClusterObjectType(type, isDecodable, options)
return zclHelper.asUnderlyingZclType.call({ global : this.global }, type, options);
}

let promise = templateUtil.ensureZclPackageId(this).then(fn.bind(this));
let typeStr = await templateUtil.ensureZclPackageId(this).then(fn.bind(this));
if ((this.isList || this.isArray || this.entryType) && !options.hash.forceNotList) {
passByReference = true;
// If we did not have a namespace provided, we can assume we're inside
// chip::app.
let listNamespace = options.hash.ns ? "chip::app::" : ""
if (isDecodable)
{
promise = promise.then(typeStr => `${listNamespace}DataModel::DecodableList<${typeStr}>`);
typeStr = `${listNamespace}DataModel::DecodableList<${typeStr}>`;
}
else
{
// Use const ${typeStr} so that consumers don't have to create non-const
// data to encode.
promise = promise.then(typeStr => `${listNamespace}DataModel::List<const ${typeStr}>`);
typeStr = `${listNamespace}DataModel::List<const ${typeStr}>`;
}
}
if (this.isNullable && !options.hash.forceNotNullable) {
passByReference = true;
// If we did not have a namespace provided, we can assume we're inside
// chip::app::.
let ns = options.hash.ns ? "chip::app::" : ""
promise = promise.then(typeStr => `${ns}DataModel::Nullable<${typeStr}>`);
typeStr = `${ns}DataModel::Nullable<${typeStr}>`;
}
if (this.isOptional && !options.hash.forceNotOptional) {
passByReference = true;
// If we did not have a namespace provided, we can assume we're inside
// chip::.
let ns = options.hash.ns ? "chip::" : ""
promise = promise.then(typeStr => `${ns}Optional<${typeStr}>`);
typeStr = `${ns}Optional<${typeStr}>`;
}
if (options.hash.isArgument && passByReference) {
promise = promise.then(typeStr => `const ${typeStr} &`);
typeStr = `const ${typeStr} &`;
}
return templateUtil.templatePromise(this.global, promise)
return templateUtil.templatePromise(this.global, Promise.resolve(typeStr))
}

function zapTypeToEncodableClusterObjectType(type, options)
Expand Down

0 comments on commit 989ddca

Please sign in to comment.