Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Dec 6, 2024
1 parent 88eaa6d commit ff52d4c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/core/src/validate/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type ValidationError =
| ValidationErrorOpcode
| ValidationErrorWithName
| ValidationErrorUpgradeability
| ValidationErrorInitializers;
| ValidationErrorInitializer;

interface ValidationErrorBase {
src: string;
Expand All @@ -79,18 +79,16 @@ interface ValidationErrorWithName extends ValidationErrorBase {
| 'internal-function-storage';
}

interface ValidationErrorInitializerGeneric extends ValidationErrorBase {
name: string;
interface ValidationErrorInitializerCall extends ValidationErrorBase {
kind: 'missing-initializer' | 'missing-initializer-call' | 'duplicate-initializer-call';
}

interface ValidationErrorInitializerOrder extends ValidationErrorBase {
name: string;
kind: 'incorrect-initializer-order';
expectedLinearization: string[];
}

type ValidationErrorInitializers = ValidationErrorInitializerGeneric | ValidationErrorInitializerOrder;
type ValidationErrorInitializer = ValidationErrorInitializerCall | ValidationErrorInitializerOrder;

interface ValidationErrorConstructor extends ValidationErrorBase {
kind: 'constructor';
Expand Down Expand Up @@ -659,7 +657,7 @@ function* getInitializerErrors(
contractDef: ContractDefinition,
deref: ASTDereferencer,
decodeSrc: SrcDecoder,
): Generator<ValidationErrorInitializers> {
): Generator<ValidationErrorInitializer> {
if (contractDef.baseContracts.length > 0) {
const baseContractDefs = contractDef.baseContracts.map(base =>
deref('ContractDefinition', base.baseName.referencedDeclaration),
Expand All @@ -677,7 +675,6 @@ function* getInitializerErrors(
if (contractInitializers.length === 0 && !skipCheck('missing-initializer', contractDef)) {
yield {
kind: 'missing-initializer',
name: contractDef.name,
src: decodeSrc(contractDef),
};
}
Expand Down Expand Up @@ -711,7 +708,6 @@ function* getInitializerErrors(
) {
yield {
kind: 'duplicate-initializer-call',
name: contractDef.name,
src: decodeSrc(fnCall),
};
}
Expand All @@ -726,7 +722,6 @@ function* getInitializerErrors(
) {
yield {
kind: 'incorrect-initializer-order',
name: contractDef.name,
src: decodeSrc(fnCall),
expectedLinearization: baseContractsWithInitializers,
};
Expand All @@ -747,7 +742,6 @@ function* getInitializerErrors(
) {
yield {
kind: 'missing-initializer-call',
name: contractDef.name,
src: decodeSrc(contractInitializer),
};
}
Expand Down

0 comments on commit ff52d4c

Please sign in to comment.