@@ -603,89 +603,172 @@ function f33(obj: { kind: 'foo', foo: string } | { kind: 'bar', bar: number }) {
603603 }
604604}
605605
606+
607+ class C10 {
608+ >C10 : Symbol(C10, Decl(controlFlowAliasing.ts, 209, 1))
609+
610+ constructor(readonly x: string | number) {
611+ >x : Symbol(C10.x, Decl(controlFlowAliasing.ts, 213, 16))
612+
613+ const thisX_isString = typeof this.x === 'string';
614+ >thisX_isString : Symbol(thisX_isString, Decl(controlFlowAliasing.ts, 214, 13))
615+ >this.x : Symbol(C10.x, Decl(controlFlowAliasing.ts, 213, 16))
616+ >this : Symbol(C10, Decl(controlFlowAliasing.ts, 209, 1))
617+ >x : Symbol(C10.x, Decl(controlFlowAliasing.ts, 213, 16))
618+
619+ const xIsString = typeof x === 'string';
620+ >xIsString : Symbol(xIsString, Decl(controlFlowAliasing.ts, 215, 13))
621+ >x : Symbol(x, Decl(controlFlowAliasing.ts, 213, 16))
622+
623+ if (thisX_isString && xIsString) {
624+ >thisX_isString : Symbol(thisX_isString, Decl(controlFlowAliasing.ts, 214, 13))
625+ >xIsString : Symbol(xIsString, Decl(controlFlowAliasing.ts, 215, 13))
626+
627+ let s: string;
628+ >s : Symbol(s, Decl(controlFlowAliasing.ts, 217, 15))
629+
630+ s = this.x;
631+ >s : Symbol(s, Decl(controlFlowAliasing.ts, 217, 15))
632+ >this.x : Symbol(C10.x, Decl(controlFlowAliasing.ts, 213, 16))
633+ >this : Symbol(C10, Decl(controlFlowAliasing.ts, 209, 1))
634+ >x : Symbol(C10.x, Decl(controlFlowAliasing.ts, 213, 16))
635+
636+ s = x;
637+ >s : Symbol(s, Decl(controlFlowAliasing.ts, 217, 15))
638+ >x : Symbol(x, Decl(controlFlowAliasing.ts, 213, 16))
639+ }
640+ }
641+ }
642+
643+ class C11 {
644+ >C11 : Symbol(C11, Decl(controlFlowAliasing.ts, 222, 1))
645+
646+ constructor(readonly x: string | number) {
647+ >x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
648+
649+ const thisX_isString = typeof this.x === 'string';
650+ >thisX_isString : Symbol(thisX_isString, Decl(controlFlowAliasing.ts, 226, 13))
651+ >this.x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
652+ >this : Symbol(C11, Decl(controlFlowAliasing.ts, 222, 1))
653+ >x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
654+
655+ const xIsString = typeof x === 'string';
656+ >xIsString : Symbol(xIsString, Decl(controlFlowAliasing.ts, 227, 13))
657+ >x : Symbol(x, Decl(controlFlowAliasing.ts, 225, 16))
658+
659+ if (thisX_isString && xIsString) {
660+ >thisX_isString : Symbol(thisX_isString, Decl(controlFlowAliasing.ts, 226, 13))
661+ >xIsString : Symbol(xIsString, Decl(controlFlowAliasing.ts, 227, 13))
662+
663+ // Some narrowings may be invalidated due to later assignments.
664+ let s: string;
665+ >s : Symbol(s, Decl(controlFlowAliasing.ts, 230, 15))
666+
667+ s = this.x;
668+ >s : Symbol(s, Decl(controlFlowAliasing.ts, 230, 15))
669+ >this.x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
670+ >this : Symbol(C11, Decl(controlFlowAliasing.ts, 222, 1))
671+ >x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
672+
673+ s = x;
674+ >s : Symbol(s, Decl(controlFlowAliasing.ts, 230, 15))
675+ >x : Symbol(x, Decl(controlFlowAliasing.ts, 225, 16))
676+ }
677+ else {
678+ this.x = 10;
679+ >this.x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
680+ >this : Symbol(C11, Decl(controlFlowAliasing.ts, 222, 1))
681+ >x : Symbol(C11.x, Decl(controlFlowAliasing.ts, 225, 16))
682+
683+ x = 10;
684+ >x : Symbol(x, Decl(controlFlowAliasing.ts, 225, 16))
685+ }
686+ }
687+ }
688+
606689// Mixing of aliased discriminants and conditionals
607690
608691function f40(obj: { kind: 'foo', foo?: string } | { kind: 'bar', bar?: number }) {
609- >f40 : Symbol(f40, Decl(controlFlowAliasing.ts, 209 , 1))
610- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 213 , 13))
611- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 213 , 19))
612- >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 213 , 32))
613- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 213 , 51))
614- >bar : Symbol(bar, Decl(controlFlowAliasing.ts, 213 , 64))
692+ >f40 : Symbol(f40, Decl(controlFlowAliasing.ts, 239 , 1))
693+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 243 , 13))
694+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 243 , 19))
695+ >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 243 , 32))
696+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 243 , 51))
697+ >bar : Symbol(bar, Decl(controlFlowAliasing.ts, 243 , 64))
615698
616699 const { kind } = obj;
617- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 214 , 11))
618- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 213 , 13))
700+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 244 , 11))
701+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 243 , 13))
619702
620703 const isFoo = kind == 'foo';
621- >isFoo : Symbol(isFoo, Decl(controlFlowAliasing.ts, 215 , 9))
622- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 214 , 11))
704+ >isFoo : Symbol(isFoo, Decl(controlFlowAliasing.ts, 245 , 9))
705+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 244 , 11))
623706
624707 if (isFoo && obj.foo) {
625- >isFoo : Symbol(isFoo, Decl(controlFlowAliasing.ts, 215 , 9))
626- >obj.foo : Symbol(foo, Decl(controlFlowAliasing.ts, 213 , 32))
627- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 213 , 13))
628- >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 213 , 32))
708+ >isFoo : Symbol(isFoo, Decl(controlFlowAliasing.ts, 245 , 9))
709+ >obj.foo : Symbol(foo, Decl(controlFlowAliasing.ts, 243 , 32))
710+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 243 , 13))
711+ >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 243 , 32))
629712
630713 let t: string = obj.foo;
631- >t : Symbol(t, Decl(controlFlowAliasing.ts, 217 , 11))
632- >obj.foo : Symbol(foo, Decl(controlFlowAliasing.ts, 213 , 32))
633- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 213 , 13))
634- >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 213 , 32))
714+ >t : Symbol(t, Decl(controlFlowAliasing.ts, 247 , 11))
715+ >obj.foo : Symbol(foo, Decl(controlFlowAliasing.ts, 243 , 32))
716+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 243 , 13))
717+ >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 243 , 32))
635718 }
636719}
637720
638721// Unsupported narrowing of destructured payload by destructured discriminant
639722
640723type Data = { kind: 'str', payload: string } | { kind: 'num', payload: number };
641- >Data : Symbol(Data, Decl(controlFlowAliasing.ts, 219 , 1))
642- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 223 , 13))
643- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 223 , 26))
644- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 223 , 48))
645- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 223 , 61))
724+ >Data : Symbol(Data, Decl(controlFlowAliasing.ts, 249 , 1))
725+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 253 , 13))
726+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 253 , 26))
727+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 253 , 48))
728+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 253 , 61))
646729
647730function gg2(obj: Data) {
648- >gg2 : Symbol(gg2, Decl(controlFlowAliasing.ts, 223 , 80))
649- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 225 , 13))
650- >Data : Symbol(Data, Decl(controlFlowAliasing.ts, 219 , 1))
731+ >gg2 : Symbol(gg2, Decl(controlFlowAliasing.ts, 253 , 80))
732+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 255 , 13))
733+ >Data : Symbol(Data, Decl(controlFlowAliasing.ts, 249 , 1))
651734
652735 if (obj.kind === 'str') {
653- >obj.kind : Symbol(kind, Decl(controlFlowAliasing.ts, 223 , 13), Decl(controlFlowAliasing.ts, 223 , 48))
654- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 225 , 13))
655- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 223 , 13), Decl(controlFlowAliasing.ts, 223 , 48))
736+ >obj.kind : Symbol(kind, Decl(controlFlowAliasing.ts, 253 , 13), Decl(controlFlowAliasing.ts, 253 , 48))
737+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 255 , 13))
738+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 253 , 13), Decl(controlFlowAliasing.ts, 253 , 48))
656739
657740 let t: string = obj.payload;
658- >t : Symbol(t, Decl(controlFlowAliasing.ts, 227 , 11))
659- >obj.payload : Symbol(payload, Decl(controlFlowAliasing.ts, 223 , 26))
660- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 225 , 13))
661- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 223 , 26))
741+ >t : Symbol(t, Decl(controlFlowAliasing.ts, 257 , 11))
742+ >obj.payload : Symbol(payload, Decl(controlFlowAliasing.ts, 253 , 26))
743+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 255 , 13))
744+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 253 , 26))
662745 }
663746 else {
664747 let t: number = obj.payload;
665- >t : Symbol(t, Decl(controlFlowAliasing.ts, 230 , 11))
666- >obj.payload : Symbol(payload, Decl(controlFlowAliasing.ts, 223 , 61))
667- >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 225 , 13))
668- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 223 , 61))
748+ >t : Symbol(t, Decl(controlFlowAliasing.ts, 260 , 11))
749+ >obj.payload : Symbol(payload, Decl(controlFlowAliasing.ts, 253 , 61))
750+ >obj : Symbol(obj, Decl(controlFlowAliasing.ts, 255 , 13))
751+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 253 , 61))
669752 }
670753}
671754
672755function foo({ kind, payload }: Data) {
673- >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 232 , 1))
674- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 234 , 14))
675- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 234 , 20))
676- >Data : Symbol(Data, Decl(controlFlowAliasing.ts, 219 , 1))
756+ >foo : Symbol(foo, Decl(controlFlowAliasing.ts, 262 , 1))
757+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 264 , 14))
758+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 264 , 20))
759+ >Data : Symbol(Data, Decl(controlFlowAliasing.ts, 249 , 1))
677760
678761 if (kind === 'str') {
679- >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 234 , 14))
762+ >kind : Symbol(kind, Decl(controlFlowAliasing.ts, 264 , 14))
680763
681764 let t: string = payload;
682- >t : Symbol(t, Decl(controlFlowAliasing.ts, 236 , 11))
683- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 234 , 20))
765+ >t : Symbol(t, Decl(controlFlowAliasing.ts, 266 , 11))
766+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 264 , 20))
684767 }
685768 else {
686769 let t: number = payload;
687- >t : Symbol(t, Decl(controlFlowAliasing.ts, 239 , 11))
688- >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 234 , 20))
770+ >t : Symbol(t, Decl(controlFlowAliasing.ts, 269 , 11))
771+ >payload : Symbol(payload, Decl(controlFlowAliasing.ts, 264 , 20))
689772 }
690773}
691774
0 commit comments