From 0dc5f7e9cc4055fa00fca9fcfed7a1c8fa1d1018 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sat, 6 Aug 2022 15:37:08 +0800 Subject: [PATCH 1/4] handle void to void during `convertExpression` --- src/compiler.ts | 5 +++++ tests/compiler/variable-access-in-initializer.json | 1 + tests/compiler/variable-access-in-initializer.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/src/compiler.ts b/src/compiler.ts index 618d4636e3..5de34f3dce 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3520,6 +3520,11 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { var module = this.module; + // void to void + if (fromType.kind == TypeKind.VOID && toType.kind == TypeKind.VOID) { + return expr; + } + // void to any if (fromType.kind == TypeKind.VOID) { assert(toType.kind != TypeKind.VOID); // convertExpression should not be called with void -> void diff --git a/tests/compiler/variable-access-in-initializer.json b/tests/compiler/variable-access-in-initializer.json index 44ccbd7698..824a0f8e52 100644 --- a/tests/compiler/variable-access-in-initializer.json +++ b/tests/compiler/variable-access-in-initializer.json @@ -3,6 +3,7 @@ ], "stderr": [ "TS2448: Variable 'variable-access-in-initializer/a' used before its declaration.", + "TS2448: Variable 'variable-access-in-initializer/c' used before its declaration.", "TS2448: Variable 'variable-access-in-initializer/test~b' used before its declaration.", "EOF" ] diff --git a/tests/compiler/variable-access-in-initializer.ts b/tests/compiler/variable-access-in-initializer.ts index 3d3ce749e4..85cfbe80ed 100644 --- a/tests/compiler/variable-access-in-initializer.ts +++ b/tests/compiler/variable-access-in-initializer.ts @@ -1,4 +1,5 @@ var a = (a = 4, 3); // TS2448 +let c = typeof c; function test(): void { let b = (b = 4, 3); // TS2448 From b412c7582f7675c7ec91eac5a8c590ee81268fca Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sat, 6 Aug 2022 19:23:44 +0800 Subject: [PATCH 2/4] Update src/compiler.ts Co-authored-by: Max Graey --- src/compiler.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 5de34f3dce..dcd371a29f 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3521,13 +3521,12 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; // void to void - if (fromType.kind == TypeKind.VOID && toType.kind == TypeKind.VOID) { - return expr; - } - - // void to any if (fromType.kind == TypeKind.VOID) { - assert(toType.kind != TypeKind.VOID); // convertExpression should not be called with void -> void + if (toType.kind == TypeKind.VOID) { + // void to void + return expr; + } + // void to any this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, reportNode.range, fromType.toString(), toType.toString() From bb7c74fb00e4e9be6b928ffd593e01b1ae916985 Mon Sep 17 00:00:00 2001 From: Max Graey Date: Sat, 6 Aug 2022 14:24:53 +0300 Subject: [PATCH 3/4] Update src/compiler.ts --- src/compiler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index dcd371a29f..0216b791b7 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3520,7 +3520,6 @@ export class Compiler extends DiagnosticEmitter { ): ExpressionRef { var module = this.module; - // void to void if (fromType.kind == TypeKind.VOID) { if (toType.kind == TypeKind.VOID) { // void to void From 1f6878cf387354e581ccf5468b8b5ffa8668110f Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Sun, 21 Aug 2022 10:41:39 +0800 Subject: [PATCH 4/4] Update src/compiler.ts Co-authored-by: dcode --- src/compiler.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index eca770274d..a606d6873b 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3438,7 +3438,8 @@ export class Compiler extends DiagnosticEmitter { if (fromType.kind == TypeKind.VOID) { if (toType.kind == TypeKind.VOID) { - // void to void + // void to void: Can happen as a result of a foregoing error. Since we + // have an `expr` here that is already supposed to be void, return it. return expr; } // void to any