Skip to content

Commit d83a0fd

Browse files
authored
fix(world): support functions with missing argument names in system libraries (#3671)
1 parent fb2745a commit d83a0fd

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

.changeset/thin-insects-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/world": patch
3+
---
4+
5+
Adds support for functions with missing argument names in system libraries.

packages/world/ts/node/render-solidity/renderSystemLibrary.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ export function renderSystemLibrary(options: RenderSystemLibraryOptions) {
2222
storeImportPath,
2323
} = options;
2424

25-
// Remove `payable` from stateMutability for library functions
2625
const functions = functionsInput.map((func) => ({
2726
...func,
27+
// Format parameters (add auxiliary argument names, replace calldata location)
28+
parameters: formatParams(func.parameters),
29+
// Remove `payable` from stateMutability for library functions
2830
stateMutability: func.stateMutability.replace("payable", ""),
2931
}));
3032

@@ -158,7 +160,7 @@ function renderErrors(errors: ContractInterfaceError[]) {
158160
function renderUserTypeFunction(contractFunction: ContractInterfaceFunction, userTypeName: string) {
159161
const { name, parameters, stateMutability, returnParameters } = contractFunction;
160162

161-
const args = [`${userTypeName} self`, ...parameters].map((arg) => arg.replace(/ calldata /, " memory "));
163+
const args = [`${userTypeName} self`, ...parameters];
162164

163165
const functionSignature = `
164166
function ${name}(
@@ -183,7 +185,7 @@ function renderCallWrapperFunction(
183185
) {
184186
const { name, parameters, stateMutability, returnParameters } = contractFunction;
185187

186-
const args = [`CallWrapper memory self`, ...parameters].map((arg) => arg.replace(/ calldata /, " memory "));
188+
const args = [`CallWrapper memory self`, ...parameters];
187189

188190
const functionSignature = `
189191
function ${name}(
@@ -236,7 +238,7 @@ function renderRootCallWrapperFunction(contractFunction: ContractInterfaceFuncti
236238
return "";
237239
}
238240

239-
const args = ["RootCallWrapper memory self", ...parameters].map((arg) => arg.replace(/ calldata /, " memory "));
241+
const args = ["RootCallWrapper memory self", ...parameters];
240242

241243
const functionSignature = `
242244
function ${name}(
@@ -312,3 +314,16 @@ function renderReturnParameters(returnParameters: string[]) {
312314

313315
return `returns (${renderArguments(returnParameters)})`;
314316
}
317+
318+
function formatParams(params: string[]) {
319+
// Use auxiliary argument names for arguments without names
320+
let auxCount = 0;
321+
322+
return params
323+
.map((arg) => arg.replace(/ calldata /, " memory "))
324+
.map((arg) => {
325+
const items = arg.split(" ");
326+
const needsAux = items.length === 1 || (items.length === 2 && items[1] === "memory");
327+
return needsAux ? `${arg} __aux${auxCount++}` : arg;
328+
});
329+
}

0 commit comments

Comments
 (0)