Skip to content

Commit

Permalink
Merge pull request #570 from algorandfoundation/fix/fn_order
Browse files Browse the repository at this point in the history
fix: intermittent errors in non-class functions due to processing order
  • Loading branch information
joe-p authored Nov 5, 2024
2 parents 3e02202 + f1b7341 commit a6e6734
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2942,16 +2942,16 @@ export default class Compiler {

if (this.currentProgram !== 'lsig') this.routeAbiMethods();

while (this.pendingSubroutines.length > 0) {
this.processSubroutine(this.pendingSubroutines.pop()!);
}

Object.keys(this.compilerSubroutines).forEach((sub) => {
if (this.teal[this.currentProgram].map((t) => t.teal).includes(`callsub ${sub}`)) {
this.pushLines(this.classNode, ...this.compilerSubroutines[sub]());
}
});

while (this.pendingSubroutines.length > 0) {
this.processSubroutine(this.pendingSubroutines.pop()!);
}

this.teal[this.currentProgram] = await this.postProcessTeal(this.teal[this.currentProgram]);
this.teal[this.currentProgram] = optimizeTeal(this.teal[this.currentProgram]);
this.teal[this.currentProgram] = this.prettyTeal(this.teal[this.currentProgram]);
Expand Down Expand Up @@ -5026,10 +5026,16 @@ export default class Compiler {
.map((a) => a.getKind())
.includes(ts.SyntaxKind.ClassDeclaration);

/** True if defined in a function outside of a class */
const inFunction = defNode
.getAncestors()
.map((a) => a.getKind())
.includes(ts.SyntaxKind.FunctionDeclaration);

// This is true when we are in a non-class function and the identifier is a function parameter
const isFunctionParam = defNode.getParent()?.isKind(ts.SyntaxKind.FunctionDeclaration);

if (!inClass && !isFunctionParam) {
if (!inClass && !isFunctionParam && !inFunction) {
if (!defNode.isKind(ts.SyntaxKind.VariableDeclaration)) throw Error();
this.processNode(defNode.getInitializerOrThrow());
return;
Expand Down

0 comments on commit a6e6734

Please sign in to comment.