-
-
Notifications
You must be signed in to change notification settings - Fork 670
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
Conversation
src/module.ts
Outdated
/** 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)); | ||
} |
There was a problem hiding this comment.
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);
}
bbd3811
to
1611141
Compare
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 { |
There was a problem hiding this comment.
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]>
Fixes: #2819