Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
update variableDeclaration writers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroLabourdette committed Feb 16, 2023
1 parent 25e47fd commit 5b1391e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
19 changes: 2 additions & 17 deletions src/cairoWriter/writers/variableDeclarationStatementWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class VariableDeclarationStatementWriter extends CairoASTNodeWriter {
writeInner(node: VariableDeclarationStatement, writer: ASTWriter): SrcDesc {
assert(
node.vInitialValue !== undefined,
'Variables should be initialised. Did you use VariableDeclarationInitialiser?',
'Variables should be initialized. Did you use VariableDeclarationInitializer?',
);

const documentation = getDocumentation(node.documentation, writer);
Expand Down Expand Up @@ -68,22 +68,7 @@ export class VariableDeclarationStatementWriter extends CairoASTNodeWriter {
return [writer.write(getDeclarationForId(id))];
}
});
if (
node.vInitialValue instanceof FunctionCall &&
node.vInitialValue.vReferencedDeclaration instanceof CairoFunctionDefinition &&
node.vInitialValue.vReferencedDeclaration.functionStubKind === FunctionStubKind.StructDefStub
) {
// This local statement is needed since Cairo is not supporting member access of structs with let.
// The type hint also needs to be placed there since Cairo's default type hint is a felt.
return [
[
documentation,
`local ${declarations.join(', ')} : ${
node.vInitialValue.vReferencedDeclaration.name
} = ${writer.write(node.vInitialValue)};`,
].join('\n'),
];
} else if (declarations.length > 1 || node.vInitialValue instanceof FunctionCall) {
if (declarations.length > 1) {
return [
[
documentation,
Expand Down
2 changes: 1 addition & 1 deletion src/cairoWriter/writers/variableDeclarationWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class VariableDeclarationWriter extends CairoASTNodeWriter {
if ((node.stateVariable || node.parent instanceof SourceUnit) && isCairoConstant(node)) {
assert(node.vValue !== undefined, 'Constant should have a defined value.');
const constantValue = writer.write(node.vValue);
return [[documentation, `const ${node.name} = ${constantValue};`].join('\n')];
return [[documentation, `let ${node.name} = ${constantValue};`].join('\n')];
}

return [node.name];
Expand Down

0 comments on commit 5b1391e

Please sign in to comment.