Skip to content

fix: select correct override function #2822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2024

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);
}

if (valueIndex >= 0) this.indexes[valueIndex] = this.addCode(code);
else this.addCase(value, code);
}

/** 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.

fix

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Co-authored-by: Max Graey <maxgraey@gmail.com>
@HerrCai0907 HerrCai0907 merged commit de174c5 into AssemblyScript:main Mar 8, 2024
13 checks passed
@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