Skip to content

Commit 707fc7a

Browse files
authored
fix: handle void to void during convertExpression (#2412)
1 parent b044b71 commit 707fc7a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Diff for: src/compiler.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3436,9 +3436,13 @@ export class Compiler extends DiagnosticEmitter {
34363436
): ExpressionRef {
34373437
var module = this.module;
34383438

3439-
// void to any
34403439
if (fromType.kind == TypeKind.VOID) {
3441-
assert(toType.kind != TypeKind.VOID); // convertExpression should not be called with void -> void
3440+
if (toType.kind == TypeKind.VOID) {
3441+
// void to void: Can happen as a result of a foregoing error. Since we
3442+
// have an `expr` here that is already supposed to be void, return it.
3443+
return expr;
3444+
}
3445+
// void to any
34423446
this.error(
34433447
DiagnosticCode.Type_0_is_not_assignable_to_type_1,
34443448
reportNode.range, fromType.toString(), toType.toString()

Diff for: tests/compiler/variable-access-in-initializer.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
],
44
"stderr": [
55
"TS2448: Variable 'variable-access-in-initializer/a' used before its declaration.",
6+
"TS2448: Variable 'variable-access-in-initializer/c' used before its declaration.",
67
"TS2448: Variable 'variable-access-in-initializer/test~b' used before its declaration.",
78
"EOF"
89
]

Diff for: tests/compiler/variable-access-in-initializer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var a = (a = 4, 3); // TS2448
2+
let c = typeof c;
23

34
function test(): void {
45
let b = (b = 4, 3); // TS2448

0 commit comments

Comments
 (0)