File tree Expand file tree Collapse file tree 6 files changed +4472
-3
lines changed
Expand file tree Collapse file tree 6 files changed +4472
-3
lines changed Original file line number Diff line number Diff line change @@ -6618,6 +6618,7 @@ export class Compiler extends DiagnosticEmitter {
66186618 ) ;
66196619 let overrideInstances = this . resolver . resolveOverrides ( instance ) ;
66206620 if ( overrideInstances ) {
6621+ let mostRecentInheritanceMapping = new Map < Class , Class > ( ) ;
66216622 for ( let i = 0 , k = overrideInstances . length ; i < k ; ++ i ) {
66226623 let overrideInstance = overrideInstances [ i ] ;
66236624 if ( ! overrideInstance . is ( CommonFlags . Compiled ) ) continue ; // errored
@@ -6680,7 +6681,18 @@ export class Compiler extends DiagnosticEmitter {
66806681 if ( instanceMembers && instanceMembers . has ( instance . declaration . name . text ) ) {
66816682 continue ; // skip those not inheriting
66826683 }
6683- builder . addCase ( extender . id , stmts ) ;
6684+ if ( mostRecentInheritanceMapping . has ( extender ) ) {
6685+ let currentRecentParent = assert ( mostRecentInheritanceMapping . get ( extender ) ) ;
6686+ if ( currentRecentParent . extends ( classInstance ) ) {
6687+ // already find recent parent, keep old stmt
6688+ } else {
6689+ mostRecentInheritanceMapping . set ( extender , classInstance ) ;
6690+ builder . replaceCase ( extender . id , stmts ) ;
6691+ }
6692+ } else {
6693+ mostRecentInheritanceMapping . set ( extender , classInstance ) ;
6694+ builder . addCase ( extender . id , stmts ) ;
6695+ }
66846696 }
66856697 }
66866698 }
Original file line number Diff line number Diff line change @@ -3418,16 +3418,27 @@ export class SwitchBuilder {
34183418 this . condition = condition ;
34193419 }
34203420
3421+ /** Replace case to the specified branch. */
3422+ replaceCase ( value : i32 , code : ExpressionRef [ ] ) : void {
3423+ let valueIndex = this . values . indexOf ( value ) ;
3424+ assert ( valueIndex >= 0 ) ;
3425+ this . indexes [ valueIndex ] = this . addCode ( code ) ;
3426+ }
3427+
34213428 /** Links a case to the specified branch. */
34223429 addCase ( value : i32 , code : ExpressionRef [ ] ) : void {
3430+ this . values . push ( value ) ;
3431+ this . indexes . push ( this . addCode ( code ) ) ;
3432+ }
3433+
3434+ private addCode ( code : ExpressionRef [ ] ) : i32 {
34233435 let cases = this . cases ;
34243436 let index = cases . indexOf ( code ) ;
34253437 if ( index < 0 ) {
34263438 index = cases . length ;
34273439 cases . push ( code ) ;
34283440 }
3429- this . values . push ( value ) ;
3430- this . indexes . push ( index ) ;
3441+ return index ;
34313442 }
34323443
34333444 /** Links the default branch. */
You can’t perform that action at this time.
0 commit comments