Skip to content

fix: handle void to void during convertExpression #2412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3436,9 +3436,13 @@ export class Compiler extends DiagnosticEmitter {
): ExpressionRef {
var module = this.module;

// 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: 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
this.error(
DiagnosticCode.Type_0_is_not_assignable_to_type_1,
reportNode.range, fromType.toString(), toType.toString()
Expand Down
1 change: 1 addition & 0 deletions tests/compiler/variable-access-in-initializer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
1 change: 1 addition & 0 deletions tests/compiler/variable-access-in-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var a = (a = 4, 3); // TS2448
let c = typeof c;

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