Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error if assignment after block (#41115)
* Error if assignment after block * Update src/compiler/diagnosticMessages.json Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Fix diags * Error after block Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
- Loading branch information
1 parent
76a2ae3
commit 62f3ccd
Showing
9 changed files
with
173 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/baselines/reference/destructionAssignmentError.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
tests/cases/compiler/destructionAssignmentError.ts(6,3): error TS2695: Left side of comma operator is unused and has no side effects. | ||
tests/cases/compiler/destructionAssignmentError.ts(6,10): error TS2809: Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses. | ||
tests/cases/compiler/destructionAssignmentError.ts(11,3): error TS2695: Left side of comma operator is unused and has no side effects. | ||
tests/cases/compiler/destructionAssignmentError.ts(12,1): error TS2809: Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses. | ||
|
||
|
||
==== tests/cases/compiler/destructionAssignmentError.ts (4 errors) ==== | ||
declare function fn(): { a: 1, b: 2 } | ||
let a: number; | ||
let b: number; | ||
|
||
({ a, b } = fn()); | ||
{ a, b } = fn(); | ||
~ | ||
!!! error TS2695: Left side of comma operator is unused and has no side effects. | ||
~ | ||
!!! error TS2809: Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses. | ||
|
||
({ a, b } = | ||
fn()); | ||
|
||
{ a, b } | ||
~ | ||
!!! error TS2695: Left side of comma operator is unused and has no side effects. | ||
= fn(); | ||
~ | ||
!!! error TS2809: Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//// [destructionAssignmentError.ts] | ||
declare function fn(): { a: 1, b: 2 } | ||
let a: number; | ||
let b: number; | ||
|
||
({ a, b } = fn()); | ||
{ a, b } = fn(); | ||
|
||
({ a, b } = | ||
fn()); | ||
|
||
{ a, b } | ||
= fn(); | ||
|
||
//// [destructionAssignmentError.js] | ||
var _a, _b; | ||
var a; | ||
var b; | ||
(_a = fn(), a = _a.a, b = _a.b); | ||
{ | ||
a, b; | ||
} | ||
fn(); | ||
(_b = fn(), a = _b.a, b = _b.b); | ||
{ | ||
a, b; | ||
} | ||
fn(); |
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/destructionAssignmentError.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
=== tests/cases/compiler/destructionAssignmentError.ts === | ||
declare function fn(): { a: 1, b: 2 } | ||
>fn : Symbol(fn, Decl(destructionAssignmentError.ts, 0, 0)) | ||
>a : Symbol(a, Decl(destructionAssignmentError.ts, 0, 24)) | ||
>b : Symbol(b, Decl(destructionAssignmentError.ts, 0, 30)) | ||
|
||
let a: number; | ||
>a : Symbol(a, Decl(destructionAssignmentError.ts, 1, 3)) | ||
|
||
let b: number; | ||
>b : Symbol(b, Decl(destructionAssignmentError.ts, 2, 3)) | ||
|
||
({ a, b } = fn()); | ||
>a : Symbol(a, Decl(destructionAssignmentError.ts, 4, 2)) | ||
>b : Symbol(b, Decl(destructionAssignmentError.ts, 4, 5)) | ||
>fn : Symbol(fn, Decl(destructionAssignmentError.ts, 0, 0)) | ||
|
||
{ a, b } = fn(); | ||
>a : Symbol(a, Decl(destructionAssignmentError.ts, 1, 3)) | ||
>b : Symbol(b, Decl(destructionAssignmentError.ts, 2, 3)) | ||
>fn : Symbol(fn, Decl(destructionAssignmentError.ts, 0, 0)) | ||
|
||
({ a, b } = | ||
>a : Symbol(a, Decl(destructionAssignmentError.ts, 7, 2)) | ||
>b : Symbol(b, Decl(destructionAssignmentError.ts, 7, 5)) | ||
|
||
fn()); | ||
>fn : Symbol(fn, Decl(destructionAssignmentError.ts, 0, 0)) | ||
|
||
{ a, b } | ||
>a : Symbol(a, Decl(destructionAssignmentError.ts, 1, 3)) | ||
>b : Symbol(b, Decl(destructionAssignmentError.ts, 2, 3)) | ||
|
||
= fn(); | ||
>fn : Symbol(fn, Decl(destructionAssignmentError.ts, 0, 0)) | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/destructionAssignmentError.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
=== tests/cases/compiler/destructionAssignmentError.ts === | ||
declare function fn(): { a: 1, b: 2 } | ||
>fn : () => { a: 1; b: 2;} | ||
>a : 1 | ||
>b : 2 | ||
|
||
let a: number; | ||
>a : number | ||
|
||
let b: number; | ||
>b : number | ||
|
||
({ a, b } = fn()); | ||
>({ a, b } = fn()) : { a: 1; b: 2; } | ||
>{ a, b } = fn() : { a: 1; b: 2; } | ||
>{ a, b } : { a: number; b: number; } | ||
>a : number | ||
>b : number | ||
>fn() : { a: 1; b: 2; } | ||
>fn : () => { a: 1; b: 2; } | ||
|
||
{ a, b } = fn(); | ||
>a, b : number | ||
>a : number | ||
>b : number | ||
>fn() : { a: 1; b: 2; } | ||
>fn : () => { a: 1; b: 2; } | ||
|
||
({ a, b } = | ||
>({ a, b } =fn()) : { a: 1; b: 2; } | ||
>{ a, b } =fn() : { a: 1; b: 2; } | ||
>{ a, b } : { a: number; b: number; } | ||
>a : number | ||
>b : number | ||
|
||
fn()); | ||
>fn() : { a: 1; b: 2; } | ||
>fn : () => { a: 1; b: 2; } | ||
|
||
{ a, b } | ||
>a, b : number | ||
>a : number | ||
>b : number | ||
|
||
= fn(); | ||
>fn() : { a: 1; b: 2; } | ||
>fn : () => { a: 1; b: 2; } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
declare function fn(): { a: 1, b: 2 } | ||
let a: number; | ||
let b: number; | ||
|
||
({ a, b } = fn()); | ||
{ a, b } = fn(); | ||
|
||
({ a, b } = | ||
fn()); | ||
|
||
{ a, b } | ||
= fn(); |
Typo/stutter: the the -> the