From 5de55eafc3f61dd78172dad609ed5350dcea19fb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:46:13 -0800 Subject: [PATCH 1/2] Return freshly cached post-super flow results The shared-flow slow path has already traversed the antecedents and recorded its answer. Return that result rather than immediately walking the same control-flow graph again. Exercise fully initialized and missing-super paths across shared branches, loops, and finally blocks. --- tsc/internal/checker/flow.go | 1 + .../compiler/postSuperSharedFlow.errors.txt | 46 ++++++++ .../reference/compiler/postSuperSharedFlow.js | 81 +++++++++++++ .../compiler/postSuperSharedFlow.symbols | 96 +++++++++++++++ .../compiler/postSuperSharedFlow.types | 111 ++++++++++++++++++ .../cases/compiler/postSuperSharedFlow.ts | 39 ++++++ 6 files changed, 374 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js create mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types create mode 100644 tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts diff --git a/tsc/internal/checker/flow.go b/tsc/internal/checker/flow.go index 05daef984819d..8d14ca5258079 100644 --- a/tsc/internal/checker/flow.go +++ b/tsc/internal/checker/flow.go @@ -2630,6 +2630,7 @@ func (c *Checker) isPostSuperFlowNodeWorker(f *FlowState, flow *ast.FlowNode, no } postSuper := c.isPostSuperFlowNodeWorker(f, flow, true /*noCacheCheck*/) c.flowNodePostSuper[flow] = postSuper + return postSuper } noCacheCheck = false } diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt new file mode 100644 index 0000000000000..0cab9fc2502b8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt @@ -0,0 +1,46 @@ +postSuperSharedFlow.ts(31,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +postSuperSharedFlow.ts(32,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + + +==== postSuperSharedFlow.ts (2 errors) ==== + class Base { + value = 0; + } + + class AllPaths extends Base { + constructor(condition: boolean) { + if (condition) { + super(); + } else { + super(); + } + this.value++; + this.value++; + while (condition) { + this.value++; + condition = false; + } + try { + this.value++; + } finally { + this.value++; + } + } + } + + class MissingPath extends Base { + constructor(condition: boolean) { + if (condition) { + super(); + } + this.value++; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + this.value++; + ~~~~ +!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); + this.value++; + } + } + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js new file mode 100644 index 0000000000000..4a404845bb3b8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/postSuperSharedFlow.ts] //// + +//// [postSuperSharedFlow.ts] +class Base { + value = 0; +} + +class AllPaths extends Base { + constructor(condition: boolean) { + if (condition) { + super(); + } else { + super(); + } + this.value++; + this.value++; + while (condition) { + this.value++; + condition = false; + } + try { + this.value++; + } finally { + this.value++; + } + } +} + +class MissingPath extends Base { + constructor(condition: boolean) { + if (condition) { + super(); + } + this.value++; + this.value++; + super(); + this.value++; + } +} + + +//// [postSuperSharedFlow.js] +"use strict"; +class Base { + constructor() { + this.value = 0; + } +} +class AllPaths extends Base { + constructor(condition) { + if (condition) { + super(); + } + else { + super(); + } + this.value++; + this.value++; + while (condition) { + this.value++; + condition = false; + } + try { + this.value++; + } + finally { + this.value++; + } + } +} +class MissingPath extends Base { + constructor(condition) { + if (condition) { + super(); + } + this.value++; + this.value++; + super(); + this.value++; + } +} diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols new file mode 100644 index 0000000000000..4dd1a37a3f1b5 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols @@ -0,0 +1,96 @@ +//// [tests/cases/compiler/postSuperSharedFlow.ts] //// + +=== postSuperSharedFlow.ts === +class Base { +>Base : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + + value = 0; +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +} + +class AllPaths extends Base { +>AllPaths : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) +>Base : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + + constructor(condition: boolean) { +>condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) + + if (condition) { +>condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) + + super(); +>super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + + } else { + super(); +>super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + } + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + + while (condition) { +>condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) + + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + + condition = false; +>condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) + } + try { + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + + } finally { + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + } + } +} + +class MissingPath extends Base { +>MissingPath : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) +>Base : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + + constructor(condition: boolean) { +>condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 26, 16)) + + if (condition) { +>condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 26, 16)) + + super(); +>super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + } + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + + super(); +>super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) + + this.value++; +>this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) +>this : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) +>value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) + } +} + diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types new file mode 100644 index 0000000000000..88eb39de7c8e5 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types @@ -0,0 +1,111 @@ +//// [tests/cases/compiler/postSuperSharedFlow.ts] //// + +=== postSuperSharedFlow.ts === +class Base { +>Base : Base + + value = 0; +>value : number +>0 : 0 +} + +class AllPaths extends Base { +>AllPaths : AllPaths +>Base : Base + + constructor(condition: boolean) { +>condition : boolean + + if (condition) { +>condition : boolean + + super(); +>super() : void +>super : typeof Base + + } else { + super(); +>super() : void +>super : typeof Base + } + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + + while (condition) { +>condition : boolean + + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + + condition = false; +>condition = false : false +>condition : boolean +>false : false + } + try { + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + + } finally { + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + } + } +} + +class MissingPath extends Base { +>MissingPath : MissingPath +>Base : Base + + constructor(condition: boolean) { +>condition : boolean + + if (condition) { +>condition : boolean + + super(); +>super() : void +>super : typeof Base + } + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + + super(); +>super() : void +>super : typeof Base + + this.value++; +>this.value++ : number +>this.value : number +>this : this +>value : number + } +} + diff --git a/tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts b/tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts new file mode 100644 index 0000000000000..1d42ca36e8e57 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts @@ -0,0 +1,39 @@ +// @target: es2015 +// @strict: true + +class Base { + value = 0; +} + +class AllPaths extends Base { + constructor(condition: boolean) { + if (condition) { + super(); + } else { + super(); + } + this.value++; + this.value++; + while (condition) { + this.value++; + condition = false; + } + try { + this.value++; + } finally { + this.value++; + } + } +} + +class MissingPath extends Base { + constructor(condition: boolean) { + if (condition) { + super(); + } + this.value++; + this.value++; + super(); + this.value++; + } +} From 24a757cf5158962e85f8bc32df1aeab573d966ed Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:19:57 -0800 Subject: [PATCH 2/2] Remove non-reproducing post-super compiler test The compiler case produces the same baselines without the new return. It does not protect against repeating the completed flow traversal, so retaining it would overstate the regression coverage. --- .../compiler/postSuperSharedFlow.errors.txt | 46 -------- .../reference/compiler/postSuperSharedFlow.js | 81 ------------- .../compiler/postSuperSharedFlow.symbols | 96 --------------- .../compiler/postSuperSharedFlow.types | 111 ------------------ .../cases/compiler/postSuperSharedFlow.ts | 39 ------ 5 files changed, 373 deletions(-) delete mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt delete mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js delete mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols delete mode 100644 tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types delete mode 100644 tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt deleted file mode 100644 index 0cab9fc2502b8..0000000000000 --- a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.errors.txt +++ /dev/null @@ -1,46 +0,0 @@ -postSuperSharedFlow.ts(31,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -postSuperSharedFlow.ts(32,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. - - -==== postSuperSharedFlow.ts (2 errors) ==== - class Base { - value = 0; - } - - class AllPaths extends Base { - constructor(condition: boolean) { - if (condition) { - super(); - } else { - super(); - } - this.value++; - this.value++; - while (condition) { - this.value++; - condition = false; - } - try { - this.value++; - } finally { - this.value++; - } - } - } - - class MissingPath extends Base { - constructor(condition: boolean) { - if (condition) { - super(); - } - this.value++; - ~~~~ -!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. - this.value++; - ~~~~ -!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. - super(); - this.value++; - } - } - \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js deleted file mode 100644 index 4a404845bb3b8..0000000000000 --- a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.js +++ /dev/null @@ -1,81 +0,0 @@ -//// [tests/cases/compiler/postSuperSharedFlow.ts] //// - -//// [postSuperSharedFlow.ts] -class Base { - value = 0; -} - -class AllPaths extends Base { - constructor(condition: boolean) { - if (condition) { - super(); - } else { - super(); - } - this.value++; - this.value++; - while (condition) { - this.value++; - condition = false; - } - try { - this.value++; - } finally { - this.value++; - } - } -} - -class MissingPath extends Base { - constructor(condition: boolean) { - if (condition) { - super(); - } - this.value++; - this.value++; - super(); - this.value++; - } -} - - -//// [postSuperSharedFlow.js] -"use strict"; -class Base { - constructor() { - this.value = 0; - } -} -class AllPaths extends Base { - constructor(condition) { - if (condition) { - super(); - } - else { - super(); - } - this.value++; - this.value++; - while (condition) { - this.value++; - condition = false; - } - try { - this.value++; - } - finally { - this.value++; - } - } -} -class MissingPath extends Base { - constructor(condition) { - if (condition) { - super(); - } - this.value++; - this.value++; - super(); - this.value++; - } -} diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols deleted file mode 100644 index 4dd1a37a3f1b5..0000000000000 --- a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.symbols +++ /dev/null @@ -1,96 +0,0 @@ -//// [tests/cases/compiler/postSuperSharedFlow.ts] //// - -=== postSuperSharedFlow.ts === -class Base { ->Base : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - - value = 0; ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) -} - -class AllPaths extends Base { ->AllPaths : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) ->Base : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - - constructor(condition: boolean) { ->condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) - - if (condition) { ->condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) - - super(); ->super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - - } else { - super(); ->super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - } - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - - while (condition) { ->condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) - - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - - condition = false; ->condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 5, 16)) - } - try { - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - - } finally { - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(AllPaths, Decl(postSuperSharedFlow.ts, 2, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - } - } -} - -class MissingPath extends Base { ->MissingPath : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) ->Base : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - - constructor(condition: boolean) { ->condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 26, 16)) - - if (condition) { ->condition : Symbol(condition, Decl(postSuperSharedFlow.ts, 26, 16)) - - super(); ->super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - } - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - - super(); ->super : Symbol(Base, Decl(postSuperSharedFlow.ts, 0, 0)) - - this.value++; ->this.value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) ->this : Symbol(MissingPath, Decl(postSuperSharedFlow.ts, 23, 1)) ->value : Symbol(Base.value, Decl(postSuperSharedFlow.ts, 0, 12)) - } -} - diff --git a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types b/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types deleted file mode 100644 index 88eb39de7c8e5..0000000000000 --- a/tsc/testdata/baselines/reference/compiler/postSuperSharedFlow.types +++ /dev/null @@ -1,111 +0,0 @@ -//// [tests/cases/compiler/postSuperSharedFlow.ts] //// - -=== postSuperSharedFlow.ts === -class Base { ->Base : Base - - value = 0; ->value : number ->0 : 0 -} - -class AllPaths extends Base { ->AllPaths : AllPaths ->Base : Base - - constructor(condition: boolean) { ->condition : boolean - - if (condition) { ->condition : boolean - - super(); ->super() : void ->super : typeof Base - - } else { - super(); ->super() : void ->super : typeof Base - } - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - - while (condition) { ->condition : boolean - - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - - condition = false; ->condition = false : false ->condition : boolean ->false : false - } - try { - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - - } finally { - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - } - } -} - -class MissingPath extends Base { ->MissingPath : MissingPath ->Base : Base - - constructor(condition: boolean) { ->condition : boolean - - if (condition) { ->condition : boolean - - super(); ->super() : void ->super : typeof Base - } - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - - super(); ->super() : void ->super : typeof Base - - this.value++; ->this.value++ : number ->this.value : number ->this : this ->value : number - } -} - diff --git a/tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts b/tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts deleted file mode 100644 index 1d42ca36e8e57..0000000000000 --- a/tsc/testdata/tests/cases/compiler/postSuperSharedFlow.ts +++ /dev/null @@ -1,39 +0,0 @@ -// @target: es2015 -// @strict: true - -class Base { - value = 0; -} - -class AllPaths extends Base { - constructor(condition: boolean) { - if (condition) { - super(); - } else { - super(); - } - this.value++; - this.value++; - while (condition) { - this.value++; - condition = false; - } - try { - this.value++; - } finally { - this.value++; - } - } -} - -class MissingPath extends Base { - constructor(condition: boolean) { - if (condition) { - super(); - } - this.value++; - this.value++; - super(); - this.value++; - } -}