Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
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.

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
Loading