From 7bf2c8a40517f157996798454c8b0b295131255e Mon Sep 17 00:00:00 2001 From: Dimitar Bounov <45853363+cd1m0@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:22:25 -1000 Subject: [PATCH] Fix for #269 (#270) --- src/types/infer.ts | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/types/infer.ts b/src/types/infer.ts index ef3e3822..da4501f4 100644 --- a/src/types/infer.ts +++ b/src/types/infer.ts @@ -2484,6 +2484,29 @@ export class InferType { let name: string; let args: string[]; + const getArgABITypeStr = (arg: VariableDeclaration, isLib: boolean): string => { + const typeName = arg.vType; + + // Small hack to allow some signatures for functions in the presence of incomplete ASTs + if ( + typeName instanceof UserDefinedTypeName && + typeName.referencedDeclaration < 0 && + typeName.typeString.startsWith("contract ") + ) { + return "address"; + } + + if (isLib) { + const type = this.variableDeclarationToTypeNode(arg); + return abiTypeToLibraryCanonicalName(type); + } + + const type = this.variableDeclarationToTypeNode(arg); + const abiType = this.toABIEncodedType(type, encoderVersion); + + return abiTypeToCanonicalName(generalizeType(abiType)[0]); + }; + const encoderVersion = this.getUnitLevelAbiEncoderVersion(node); if (node instanceof VariableDeclaration) { @@ -2502,12 +2525,7 @@ export class InferType { name = node.errorName; args = node.vParameters - ? node.vParameters.vParameters.map((arg) => { - const type = this.variableDeclarationToTypeNode(arg); - const abiType = this.toABIEncodedType(type, encoderVersion); - - return abiTypeToCanonicalName(generalizeType(abiType)[0]); - }) + ? node.vParameters.vParameters.map((arg) => getArgABITypeStr(arg, false)) : []; } else { if (node instanceof FunctionDefinition && (node.name === "" || node.isConstructor)) { @@ -2524,18 +2542,9 @@ export class InferType { (node instanceof FunctionDefinition && !isVisiblityExternallyCallable(node.visibility))) ) { - args = node.vParameters.vParameters.map((arg) => { - const type = this.variableDeclarationToTypeNode(arg); - - return abiTypeToLibraryCanonicalName(type); - }); + args = node.vParameters.vParameters.map((arg) => getArgABITypeStr(arg, true)); } else { - args = node.vParameters.vParameters.map((arg) => { - const type = this.variableDeclarationToTypeNode(arg); - const abiType = this.toABIEncodedType(type, encoderVersion); - - return abiTypeToCanonicalName(generalizeType(abiType)[0]); - }); + args = node.vParameters.vParameters.map((arg) => getArgABITypeStr(arg, false)); } }