Skip to content

Commit

Permalink
Fix for #269 (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
cd1m0 committed Jul 17, 2024
1 parent 8458197 commit 7bf2c8a
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/types/infer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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));
}
}

Expand Down

0 comments on commit 7bf2c8a

Please sign in to comment.