From 989ddcaa5acd3b664999adfa54e3dc63408f216f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 3 Nov 2021 12:24:56 -0400 Subject: [PATCH] Fix isArgument handling for zapTypeToClusterObjectType for structs. (#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. --- src/app/zap-templates/templates/app/helper.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/zap-templates/templates/app/helper.js b/src/app/zap-templates/templates/app/helper.js index 57e3c4cddb14b2..4577cdf81406ec 100644 --- a/src/app/zap-templates/templates/app/helper.js +++ b/src/app/zap-templates/templates/app/helper.js @@ -367,7 +367,7 @@ 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 @@ -375,13 +375,13 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) 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`); + typeStr = `${listNamespace}DataModel::List`; } } if (this.isNullable && !options.hash.forceNotNullable) { @@ -389,19 +389,19 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) // 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)