Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.
41 changes: 34 additions & 7 deletions src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,22 +791,49 @@ 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"
) {
console.log(this.variableDeclaration.typeName.baseType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a logging here?

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