Skip to content

Commit 3a15b3f

Browse files
author
Yui T
committed
Move error test cases into separate files
1 parent 0443bfb commit 3a15b3f

20 files changed

+1785
-788
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// <auto-generated />
22
/// <reference path="types.ts" />
3+
/* @internal */
34
module ts {
45
export var Diagnostics = {
56
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },

tests/baselines/reference/destructuringParameterDeclaration1.errors.txt

Lines changed: 0 additions & 272 deletions
This file was deleted.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(32,4): error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'.
2+
Types of property '0' are incompatible.
3+
Type 'string' is not assignable to type 'undefined'.
4+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(33,4): error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'.
5+
Types of property '0' are incompatible.
6+
Type '[string]' is not assignable to type '[undefined]'.
7+
Types of property '0' are incompatible.
8+
Type 'string' is not assignable to type 'undefined'.
9+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(62,10): error TS2393: Duplicate function implementation.
10+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(63,10): error TS2393: Duplicate function implementation.
11+
12+
13+
==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts (4 errors) ====
14+
// A parameter declaration may specify either an identifier or a binding pattern.
15+
// The identifiers specified in parameter declarations and binding patterns
16+
// in a parameter list must be unique within that parameter list.
17+
18+
// If the declaration includes a type annotation, the parameter is of that type
19+
function a1([a, b, [[c]]]: [number, number, string[][]]) { }
20+
function a2(o: { x: number, a: number }) { }
21+
function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { };
22+
function a4({x, a}: { x: number, a: number }) { }
23+
24+
a1([1, 2, [["world"]]]);
25+
a1([1, 2, [["world"]], 3]);
26+
27+
// If the declaration includes an initializer expression (which is permitted only
28+
// when the parameter list occurs in conjunction with a function body),
29+
// the parameter type is the widened form (section 3.11) of the type of the initializer expression.
30+
31+
function b1(z = [undefined, null]) { };
32+
function b2(z = null, o = { x: 0, y: undefined }) { }
33+
function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
34+
35+
interface F1 {
36+
b5(z, y, [, a, b], {p, m: { q, r}});
37+
}
38+
39+
function b6([a, z, y] = [undefined, null, undefined]) { }
40+
function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { }
41+
42+
b1([1, 2, 3]); // z is widen to the type any[]
43+
b2("string", { x: 200, y: "string" });
44+
b2("string", { x: 200, y: true });
45+
b6(["string", 1, 2]); // Shouldn't be an error
46+
~~~~~~~~~~~~~~~~
47+
!!! error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'.
48+
!!! error TS2345: Types of property '0' are incompatible.
49+
!!! error TS2345: Type 'string' is not assignable to type 'undefined'.
50+
b7([["string"], 1, [[true, false]]]); // Shouldn't be an error
51+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52+
!!! error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'.
53+
!!! error TS2345: Types of property '0' are incompatible.
54+
!!! error TS2345: Type '[string]' is not assignable to type '[undefined]'.
55+
!!! error TS2345: Types of property '0' are incompatible.
56+
!!! error TS2345: Type 'string' is not assignable to type 'undefined'.
57+
58+
59+
// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
60+
enum Foo { a }
61+
function c0({z: {x, y: {j}}}) { }
62+
function c1({z} = { z: 10 }) { }
63+
function c2({z = 10}) { }
64+
function c3({b}: { b: number|string} = { b: "hello" }) { }
65+
function c5([a, b, [[c]]]) { }
66+
function c6([a, b, [[c=1]]]) { }
67+
68+
c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} }
69+
c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} }
70+
71+
c1(); // Implied type is {z:number}?
72+
c1({ z: 1 }) // Implied type is {z:number}?
73+
74+
c2({}); // Implied type is {z?: number}
75+
c2({z:1}); // Implied type is {z?: number}
76+
77+
c3({ b: 1 }); // Implied type is { b: number|string }.
78+
79+
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
80+
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
81+
82+
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
83+
// or by including an initializer.
84+
85+
function d0(x?) { }
86+
~~
87+
!!! error TS2393: Duplicate function implementation.
88+
function d0(x = 10) { }
89+
~~
90+
!!! error TS2393: Duplicate function implementation.
91+
92+
interface F2 {
93+
d3([a, b, c]?);
94+
d4({x, y, z}?);
95+
e0([a, b, c]);
96+
}
97+
98+
class C2 implements F2 {
99+
constructor() { }
100+
d3() { }
101+
d4() { }
102+
e0([a, b, c]) { }
103+
}
104+
105+
class C3 implements F2 {
106+
d3([a, b, c]) { }
107+
d4({x, y, z}) { }
108+
e0([a, b, c]) { }
109+
}
110+
111+
112+
function d5({x, y} = { x: 1, y: 2 }) { }
113+
d5(); // Parameter is optional as its declaration included an initializer
114+
115+
// Destructuring parameter declarations do not permit type annotations on the individual binding patterns,
116+
// as such annotations would conflict with the already established meaning of colons in object literals.
117+
// Type annotations must instead be written on the top- level parameter declaration
118+
119+
function e1({x: number}) { } // x has type any NOT number
120+
function e2({x}: { x: number }) { } // x is type number
121+
function e3({x}: { x?: number }) { } // x is an optional with type number
122+
function e4({x: [number,string,any] }) { } // x has type [any, any, any]
123+
function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any]
124+

tests/baselines/reference/destructuringParameterDeclaration1.js renamed to tests/baselines/reference/destructuringParameterDeclaration1ES5.js

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [destructuringParameterDeclaration1.ts]
1+
//// [destructuringParameterDeclaration1ES5.ts]
22
// A parameter declaration may specify either an identifier or a binding pattern.
33
// The identifiers specified in parameter declarations and binding patterns
44
// in a parameter list must be unique within that parameter list.
@@ -11,9 +11,6 @@ function a4({x, a}: { x: number, a: number }) { }
1111

1212
a1([1, 2, [["world"]]]);
1313
a1([1, 2, [["world"]], 3]);
14-
a1([1, "string", [["world"]]); // Error
15-
a1([1, 2, [["world"]], "string"]); // Error
16-
1714

1815
// If the declaration includes an initializer expression (which is permitted only
1916
// when the parameter list occurs in conjunction with a function body),
@@ -24,7 +21,6 @@ function b2(z = null, o = { x: 0, y: undefined }) { }
2421
function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { }
2522

2623
interface F1 {
27-
b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body
2824
b5(z, y, [, a, b], {p, m: { q, r}});
2925
}
3026

@@ -34,7 +30,6 @@ function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined
3430
b1([1, 2, 3]); // z is widen to the type any[]
3531
b2("string", { x: 200, y: "string" });
3632
b2("string", { x: 200, y: true });
37-
b2("string", { x: "string", y: true }); // Error
3833
b6(["string", 1, 2]); // Shouldn't be an error
3934
b7([["string"], 1, [[true, false]]]); // Shouldn't be an error
4035

@@ -45,39 +40,28 @@ function c0({z: {x, y: {j}}}) { }
4540
function c1({z} = { z: 10 }) { }
4641
function c2({z = 10}) { }
4742
function c3({b}: { b: number|string} = { b: "hello" }) { }
48-
function c4([z], z: number) { } // Duplicate identifier
4943
function c5([a, b, [[c]]]) { }
5044
function c6([a, b, [[c=1]]]) { }
5145

5246
c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} }
5347
c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} }
54-
c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} }
5548

56-
c1({}); // Error, implied type is {z:number}?
57-
c1({ z: true }); // Error, implied type is {z:number}?
5849
c1(); // Implied type is {z:number}?
5950
c1({ z: 1 }) // Implied type is {z:number}?
6051

6152
c2({}); // Implied type is {z?: number}
6253
c2({z:1}); // Implied type is {z?: number}
63-
c2({z:false}); // Error, implied type is {z?: number}
6454

6555
c3({ b: 1 }); // Implied type is { b: number|string }.
66-
c3({ b: true }); // Error, implied type is { b: number|string }.
6756

6857
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
6958
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
70-
c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
71-
72-
c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
7359

7460
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
7561
// or by including an initializer.
7662

7763
function d0(x?) { }
7864
function d0(x = 10) { }
79-
function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature
80-
function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature
8165

8266
interface F2 {
8367
d3([a, b, c]?);
@@ -98,11 +82,6 @@ class C3 implements F2 {
9882
e0([a, b, c]) { }
9983
}
10084

101-
class C4 implements F2 {
102-
d3([a, b, c]?) { }
103-
d4({x, y, c}) { }
104-
e0([a, b, q]) { }
105-
}
10685

10786
function d5({x, y} = { x: 1, y: 2 }) { }
10887
d5(); // Parameter is optional as its declaration included an initializer
@@ -116,13 +95,9 @@ function e2({x}: { x: number }) { } // x is type number
11695
function e3({x}: { x?: number }) { } // x is an optional with type number
11796
function e4({x: [number,string,any] }) { } // x has type [any, any, any]
11897
function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any]
119-
120-
function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier;
121-
122-
12398

12499

125-
//// [destructuringParameterDeclaration1.js]
100+
//// [destructuringParameterDeclaration1ES5.js]
126101
// A parameter declaration may specify either an identifier or a binding pattern.
127102
// The identifiers specified in parameter declarations and binding patterns
128103
// in a parameter list must be unique within that parameter list.
@@ -140,8 +115,6 @@ function a4(_a) {
140115
}
141116
a1([1, 2, [["world"]]]);
142117
a1([1, 2, [["world"]], 3]);
143-
a1([1, "string", [["world"]]]); // Error
144-
a1([1, 2, [["world"]], "string"]); // Error
145118
// If the declaration includes an initializer expression (which is permitted only
146119
// when the parameter list occurs in conjunction with a function body),
147120
// the parameter type is the widened form (section 3.11) of the type of the initializer expression.
@@ -165,7 +138,6 @@ function b7(_a) {
165138
b1([1, 2, 3]); // z is widen to the type any[]
166139
b2("string", { x: 200, y: "string" });
167140
b2("string", { x: 200, y: true });
168-
b2("string", { x: "string", y: true }); // Error
169141
b6(["string", 1, 2]); // Shouldn't be an error
170142
b7([["string"], 1, [[true, false]]]); // Shouldn't be an error
171143
// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3)
@@ -185,9 +157,6 @@ function c2(_a) {
185157
function c3(_a) {
186158
var b = (_a === void 0 ? { b: "hello" } : _a).b;
187159
}
188-
function c4(_a, z) {
189-
var z = _a[0];
190-
} // Duplicate identifier
191160
function c5(_a) {
192161
var a = _a[0], b = _a[1], c = _a[2][0][0];
193162
}
@@ -196,32 +165,19 @@ function c6(_a) {
196165
}
197166
c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} }
198167
c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} }
199-
c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} }
200-
c1({}); // Error, implied type is {z:number}?
201-
c1({ z: true }); // Error, implied type is {z:number}?
202168
c1(); // Implied type is {z:number}?
203169
c1({ z: 1 }); // Implied type is {z:number}?
204170
c2({}); // Implied type is {z?: number}
205171
c2({ z: 1 }); // Implied type is {z?: number}
206-
c2({ z: false }); // Error, implied type is {z?: number}
207172
c3({ b: 1 }); // Implied type is { b: number|string }.
208-
c3({ b: true }); // Error, implied type is { b: number|string }.
209173
c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]]
210174
c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]]
211-
c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
212-
c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer
213175
// A parameter can be marked optional by following its name or binding pattern with a question mark (?)
214176
// or by including an initializer.
215177
function d0(x) { }
216178
function d0(x) {
217179
if (x === void 0) { x = 10; }
218180
}
219-
function d1(_a) {
220-
var a = _a[0], b = _a[1], c = _a[2];
221-
} // Error, binding pattern can't be optional in implementation signature
222-
function d2(_a) {
223-
var x = _a.x, y = _a.y, z = _a.z;
224-
} // Error, binding pattern can't be optional in implementation signature
225181
var C2 = (function () {
226182
function C2() {
227183
}
@@ -246,20 +202,6 @@ var C3 = (function () {
246202
};
247203
return C3;
248204
})();
249-
var C4 = (function () {
250-
function C4() {
251-
}
252-
C4.prototype.d3 = function (_a) {
253-
var a = _a[0], b = _a[1], c = _a[2];
254-
};
255-
C4.prototype.d4 = function (_a) {
256-
var x = _a.x, y = _a.y, c = _a.c;
257-
};
258-
C4.prototype.e0 = function (_a) {
259-
var a = _a[0], b = _a[1], q = _a[2];
260-
};
261-
return C4;
262-
})();
263205
function d5(_a) {
264206
var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y;
265207
}
@@ -282,6 +224,3 @@ function e4(_a) {
282224
function e5(_a) {
283225
var _b = _a.x, a = _b[0], b = _b[1], c = _b[2];
284226
} // x has type [any, any, any]
285-
function e6(_a) {
286-
var _b = _a.x, number = _b[0], number = _b[1], number = _b[2];
287-
} // should be an error, duplicate identifier;

0 commit comments

Comments
 (0)