Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions e2e/packages/contracts/src/codegen/world/IWorld.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { System } from "@latticexyz/world/src/System.sol";

contract AddressPayableArraySystem is System {
function getAddressPayableArray(address payable[] memory array) public pure returns (address payable[] memory) {
return array;
}
}
37 changes: 13 additions & 24 deletions packages/common/src/codegen/utils/contractToInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,8 @@ export function contractToInterface(
function parseParameter({ name, typeName, storageLocation }: VariableDeclaration): string {
let typedNameWithLocation = "";

const { name: flattenedTypeName, stateMutability } = flattenTypeName(typeName);
// type name (e.g. uint256)
typedNameWithLocation += flattenedTypeName;
// optional mutability (e.g. address payable)
if (stateMutability !== null) {
typedNameWithLocation += ` ${stateMutability}`;
}
typedNameWithLocation += flattenTypeName(typeName);
// location, when relevant (e.g. string memory)
if (storageLocation !== null) {
typedNameWithLocation += ` ${storageLocation}`;
Expand All @@ -120,23 +115,20 @@ function parseParameter({ name, typeName, storageLocation }: VariableDeclaration
return typedNameWithLocation;
}

function flattenTypeName(typeName: TypeName | null): { name: string; stateMutability: string | null } {
function flattenTypeName(typeName: TypeName | null): string {
if (typeName === null) {
return {
name: "",
stateMutability: null,
};
return "";
}
if (typeName.type === "ElementaryTypeName") {
return {
name: typeName.name,
stateMutability: typeName.stateMutability,
};
if (typeName.stateMutability !== null) {
// for elementary types mutability can only be `payable`, and should be part of the elementary type name
// meaning that `address payable[]` is correct, not `address[] payable`
return `${typeName.name} ${typeName.stateMutability}`;
} else {
return typeName.name;
}
} else if (typeName.type === "UserDefinedTypeName") {
return {
name: typeName.namePath,
stateMutability: null,
};
return typeName.namePath;
} else if (typeName.type === "ArrayTypeName") {
let length = "";
if (typeName.length?.type === "NumberLiteral") {
Expand All @@ -145,11 +137,8 @@ function flattenTypeName(typeName: TypeName | null): { name: string; stateMutabi
length = typeName.length.name;
}

const { name, stateMutability } = flattenTypeName(typeName.baseTypeName);
return {
name: `${name}[${length}]`,
stateMutability,
};
const name = flattenTypeName(typeName.baseTypeName);
return `${name}[${length}]`;
} else {
// TODO function types are unsupported but could be useful
throw new MUDError(`Invalid typeName.type ${typeName.type}`);
Expand Down
7 changes: 7 additions & 0 deletions test/system-libraries/src/namespaces/a/ASystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ contract ASystem is System {
Value.set(values[3]);
}
*/

/*
// TODO: support this case
function getAddressPayableArray(address payable[] memory array) public pure returns (address payable[] memory) {
return array;
}
*/
}
Loading