Skip to content

Conversation

@HerrCai0907
Copy link
Member

Fixes: #2819

src/module.ts Outdated
Comment on lines 3421 to 3432
/** Replace case to the specified branch. */
replaceCase(value: i32, code: ExpressionRef[]): void {
let valueIndex = this.values.indexOf(value);
assert(valueIndex >= 0);
this.indexes[valueIndex] = this.addCode(code);
}

/** Links a case to the specified branch. */
addCase(value: i32, code: ExpressionRef[]): void {
this.values.push(value);
this.indexes.push(this.addCode(code));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about merge replaceCase and addCase into one upsertCase method? This will simplify code above to something like:

const hasInheritance = mostRecentInheritanceMapping.has(extender);
if (!hasInheritance || !mostRecentInheritanceMapping.get(extender).extends(classInstance)) {
  mostRecentInheritanceMapping.set(extender, classInstance);
  builder.upsertCase(extender.id, stmts);
}

}

/** Links a case to the specified branch. */
addCase(value: i32, code: ExpressionRef[]): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addCase quite small and uses only once. I guess better to remove it and use their body's code in addOrReplaceCase directly.

Co-authored-by: Max Graey <[email protected]>
@HerrCai0907 HerrCai0907 merged commit de174c5 into AssemblyScript:main Mar 8, 2024
@HerrCai0907 HerrCai0907 deleted the fix/override branch March 8, 2024 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect overriden function call

4 participants