Skip to content

Commit

Permalink
fix: select correct override function (#2822)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrCai0907 committed Mar 8, 2024
1 parent 4655745 commit de174c5
Show file tree
Hide file tree
Showing 6 changed files with 4,472 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6618,6 +6618,7 @@ export class Compiler extends DiagnosticEmitter {
);
let overrideInstances = this.resolver.resolveOverrides(instance);
if (overrideInstances) {
let mostRecentInheritanceMapping = new Map<Class, Class>();
for (let i = 0, k = overrideInstances.length; i < k; ++i) {
let overrideInstance = overrideInstances[i];
if (!overrideInstance.is(CommonFlags.Compiled)) continue; // errored
Expand Down Expand Up @@ -6680,7 +6681,13 @@ export class Compiler extends DiagnosticEmitter {
if (instanceMembers && instanceMembers.has(instance.declaration.name.text)) {
continue; // skip those not inheriting
}
builder.addCase(extender.id, stmts);
if (
!mostRecentInheritanceMapping.has(extender) ||
!assert(mostRecentInheritanceMapping.get(extender)).extends(classInstance)
) {
mostRecentInheritanceMapping.set(extender, classInstance);
builder.addOrReplaceCase(extender.id, stmts);
}
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3418,16 +3418,32 @@ export class SwitchBuilder {
this.condition = condition;
}

/** Links a case to the specified branch, replace old case if it is linked. */
addOrReplaceCase(value: i32, code: ExpressionRef[]): void {
const valueIndex = this.values.indexOf(value);
const codeIndex = this.addCode(code);
if (valueIndex >= 0) {
this.indexes[valueIndex] = codeIndex;
} else {
this.values.push(value);
this.indexes.push(codeIndex);
}
}

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

private addCode(code: ExpressionRef[]): i32 {
let cases = this.cases;
let index = cases.indexOf(code);
if (index < 0) {
index = cases.length;
cases.push(code);
}
this.values.push(value);
this.indexes.push(index);
return index;
}

/** Links the default branch. */
Expand Down

0 comments on commit de174c5

Please sign in to comment.