Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow override keyword in human-readable ABI and improve error messag…
…es (#4514, #4548).
  • Loading branch information
ricmoo committed Feb 1, 2024
1 parent 98496bc commit be5ec2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src.ts/abi/fragments.ts
Expand Up @@ -121,11 +121,11 @@ function setify(items: Array<string>): ReadonlySet<string> {
return Object.freeze(result);
}

const _kwVisibDeploy = "external public payable";
const _kwVisibDeploy = "external public payable override";
const KwVisibDeploy = setify(_kwVisibDeploy.split(" "));

// Visibility Keywords
const _kwVisib = "constant external internal payable private public pure view";
const _kwVisib = "constant external internal payable private public pure view override";
const KwVisib = setify(_kwVisib.split(" "));

const _kwTypes = "constructor error event fallback function receive struct";
Expand Down Expand Up @@ -218,7 +218,10 @@ class TokenString {

// Pops and returns the value of the next token if it is `type`; throws if out of tokens
popType(type: string): string {
if (this.peek().type !== type) { throw new Error(`expected ${ type }; got ${ JSON.stringify(this.peek()) }`); }
if (this.peek().type !== type) {
const top = this.peek();
throw new Error(`expected ${ type }; got ${ top.type } ${ JSON.stringify(top.text) }`);
}
return this.pop().text;
}

Expand Down Expand Up @@ -471,7 +474,7 @@ function consumeGas(tokens: TokenString): null | bigint {

function consumeEoi(tokens: TokenString): void {
if (tokens.length) {
throw new Error(`unexpected tokens: ${ tokens.toString() }`);
throw new Error(`unexpected tokens at offset ${ tokens.offset }: ${ tokens.toString() }`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src.ts/abi/interface.ts
Expand Up @@ -342,8 +342,8 @@ export class Interface {
for (const a of abi) {
try {
frags.push(Fragment.from(a));
} catch (error) {
console.log("EE", error);
} catch (error: any) {
console.log(`[Warning] Invalid Fragment ${ JSON.stringify(a) }:`, error.message);
}
}

Expand Down

0 comments on commit be5ec2d

Please sign in to comment.