Skip to content

Commit

Permalink
error message on missing storage type args
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-p committed Jul 13, 2023
1 parent f715786 commit 5c9657d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2908,18 +2908,26 @@ export default class Compiler {
if (['BoxMap', 'GlobalStateMap', 'LocalStateMap', 'BoxKey', 'GlobalStateKey', 'LocalStateKey'].includes(klass)) {
let props: StorageProp;
const type = klass.toLocaleLowerCase().replace('state', '').replace('map', '').replace('key', '');
const typeArgs = node.initializer.typeArguments;

if (typeArgs === undefined) {
throw new Error('Type arguments must be specified for storage properties');
}

if (klass.includes('Map')) {
if (typeArgs.length !== 2) throw new Error(`Expected 2 type arguments for ${klass}`);
props = {
type,
keyType: this.getABIType(node.initializer.typeArguments![0].getText()),
valueType: this.getABIType(node.initializer.typeArguments![1].getText()),
keyType: this.getABIType(typeArgs[0].getText()),
valueType: this.getABIType(typeArgs[1].getText()),
};
} else {
if (typeArgs.length !== 1) throw new Error(`Expected a type argument for ${klass}`);

props = {
type,
keyType: 'bytes',
valueType: this.getABIType(node.initializer.typeArguments![0].getText()),
valueType: this.getABIType(typeArgs[0].getText()),
};
}

Expand Down

0 comments on commit 5c9657d

Please sign in to comment.