Skip to content
Merged
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
6 changes: 6 additions & 0 deletions fixtures/solc-0.8/input/Foo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ contract Foo is Bar {
* @dev and a function
*/
function foo(BarTestStruct calldata a, BarTestEnum b) external {}

function bar(BarTestStruct[] calldata a) external pure returns (BarTestStruct[] memory) {
return a;
}

function baz(BarTestEnum[] calldata b) external {}
}
12 changes: 12 additions & 0 deletions src/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ Generated by [AVA](https://avajs.dev).
and a function␊
### \`bar([struct TestStruct[]](fixtures/solc-0.8/output/Bar#teststruct) a) → [struct TestStruct[]](fixtures/solc-0.8/output/Bar#teststruct)\` (external)␊
### \`baz([enum TestEnum[]](fixtures/solc-0.8/output/Bar#testenum) b)\` (external)␊
Expand Down
Binary file modified src/cli.test.ts.snap
Binary file not shown.
47 changes: 40 additions & 7 deletions src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,22 +791,55 @@ export class SourceTypedVariable {
}

get isLinkable(): boolean {
return (
this.variableDeclaration.typeName?.nodeType === "UserDefinedTypeName"
);
if (!this.variableDeclaration.typeName) {
return false;
}

if (this.variableDeclaration.typeName.nodeType === "UserDefinedTypeName") {
return true;
}

if (this.variableDeclaration.typeName.nodeType === "ArrayTypeName") {
if (
this.variableDeclaration.typeName.baseType.nodeType ===
"UserDefinedTypeName"
) {
return true;
}
}

return false;
}

get link(): string {
if (!this.isLinkable) {
throw new Error("Only UserDefinedTypeName can be linked");
}

if (this.variableDeclaration.typeName?.nodeType !== "UserDefinedTypeName") {
throw new Error("Only UserDefinedTypeName can be linked");
if (!this.variableDeclaration.typeName) {
throw new Error("Only linkable types can be linked");
}

const referencedNodeId =
this.variableDeclaration.typeName.referencedDeclaration;
let referencedNodeId: number;

if (this.variableDeclaration.typeName.nodeType === "ArrayTypeName") {
if (
this.variableDeclaration.typeName.baseType.nodeType ===
"UserDefinedTypeName"
) {
referencedNodeId =
this.variableDeclaration.typeName.baseType.referencedDeclaration;
} else {
throw new Error("Only arrays of UserDefinedTypeName can be linked");
}
} else if (
this.variableDeclaration.typeName.nodeType === "UserDefinedTypeName"
) {
referencedNodeId =
this.variableDeclaration.typeName.referencedDeclaration;
} else {
throw new Error("Only UserDefinedTypeName can be linked");
}

const { node } =
this.func.contract.source.resolveNodeById(referencedNodeId);
Expand Down
Loading