Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra committed Aug 28, 2017
1 parent d65d9b2 commit 9b6de0c
Show file tree
Hide file tree
Showing 21 changed files with 537 additions and 77 deletions.
18 changes: 10 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference path="moduleNameResolver.ts"/>
/// <reference path="binder.ts"/>
/// <reference path="symbolWalker.ts" />
// /// <reference types="node"/>
// declare var console: Console;

/* @internal */
namespace ts {
Expand Down Expand Up @@ -6615,17 +6613,19 @@ namespace ts {
return getTypeOfSymbol(lastOrUndefined(signature.parameters));
}

function getRestTypeOfSignature(signature: Signature, pos: number): Type {
function getRestTypeOfSignature(signature: Signature, pos?: number): Type {
const arrIdx = pos - (signature.parameters.length - 1);
if (signature.hasRestParameter) {
const type = getRestConstraintOfSignature(signature);
if (isArrayType(type)) {
return (<TypeReference>type).typeArguments[0];
}
else if (isTupleLikeType(type)) {
const symbol = getPropertyOfObjectType(getApparentType(type), arrIdx + "" as __String);
return symbol ? getIndexedAccessType(type, pos !== undefined ? getLiteralType(arrIdx) : globalNumberType) : neverType;
}
else if (isArrayLikeType(type)) {
return getIndexedAccessType(type, getLiteralType(arrIdx));
// const symbol = getPropertyOfObjectType(getApparentType(type), arrIdx + "" as __String);
// return symbol ? getIndexedAccessType(type, getLiteralType(arrIdx)) : neverType;
return getIndexedAccessType(type, pos !== undefined ? getLiteralType(arrIdx) : globalNumberType);
}
}
return anyType;
Expand Down Expand Up @@ -10671,7 +10671,8 @@ namespace ts {
if (type === inference.typeParameter) {
return inference;
}
else if ((type as IndexedAccessType).objectType === inference.typeParameter) {
else if ((type as IndexedAccessType).objectType === inference.typeParameter &&
isTypeInstanceOf((type as IndexedAccessType).indexType, globalNumberType)) {
return inference;
}
}
Expand Down Expand Up @@ -18225,7 +18226,8 @@ namespace ts {

// Only check rest parameter type if it's not a binding pattern. Since binding patterns are
// not allowed in a rest parameter, we already have an error from checkGrammarParameterList.
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayLikeType(getTypeOfSymbol(node.symbol))) {
const type = getTypeOfSymbol(node.symbol);
if (node.dotDotDotToken && !isBindingPattern(node.name) && (!isArrayLikeType(type) || type === anyType)) {
error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,20): error TS2523: 'yield' expressions cannot be used in a parameter initializer.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,26): error TS1005: ',' expected.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS1138: Parameter declaration expected.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,34): error TS1005: ';' expected.


==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (5 errors) ====
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (6 errors) ====
function * foo(a = yield => yield) {
~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
~~~~~
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
~~
!!! error TS1005: ',' expected.
~~~~~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,30): error TS1109: Expression expected.
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,33): error TS1138: Parameter declaration expected.
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,33): error TS2304: Cannot find name 'await'.
Expand All @@ -8,10 +9,12 @@ tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclarati
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,53): error TS1109: Expression expected.


==== tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts (8 errors) ====
==== tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts (9 errors) ====
async function foo(a = await => await): Promise<void> {
~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
~~~~~
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~~
!!! error TS1109: Expression expected.
~~~~~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,30): error TS1109: Expression expected.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,33): error TS1138: Parameter declaration expected.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,33): error TS2304: Cannot find name 'await'.
Expand All @@ -8,10 +9,12 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,53): error TS1109: Expression expected.


==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts (8 errors) ====
==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts (9 errors) ====
async function foo(a = await => await): Promise<void> {
~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
~~~~~
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~~
!!! error TS1109: Expression expected.
~~~~~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,30): error TS1109: Expression expected.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS1138: Parameter declaration expected.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS2304: Cannot find name 'await'.
Expand All @@ -8,10 +9,12 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,53): error TS1109: Expression expected.


==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts (8 errors) ====
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts (9 errors) ====
async function foo(a = await => await): Promise<void> {
~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
~~~~~
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~~
!!! error TS1109: Expression expected.
~~~~~
Expand Down
20 changes: 0 additions & 20 deletions tests/baselines/reference/destructureGenerics.errors.txt

This file was deleted.

8 changes: 0 additions & 8 deletions tests/baselines/reference/destructureGenerics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ declare function f<T extends any[]>(...args: T): T;
var x = f(1,2);
var x: [1, 2];
declare function g<T extends [number, number]>(...args: T): T;
var y = g(1); // error
var y: [1];
var z = g(1,2);
var z: [1,2];
var a = g(1,2,3); // error
var a: [1,2,3];
declare function h<T>(...args: T[]): T;
var b = h(1,2,3);
var b: number;
Expand All @@ -17,11 +13,7 @@ var b: number;
//// [destructureGenerics.js]
var x = f(1, 2);
var x;
var y = g(1); // error
var y;
var z = g(1, 2);
var z;
var a = g(1, 2, 3); // error
var a;
var b = h(1, 2, 3);
var b;
48 changes: 29 additions & 19 deletions tests/baselines/reference/destructureGenerics.symbols
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
=== tests/cases/compiler/destructureGenerics.ts ===
// declare function f<T extends any[]>(...args: T): T;
// var x = f(1,2);
// var x: number[];
declare function f<T extends any[]>(...args: T): T;
>f : Symbol(f, Decl(destructureGenerics.ts, 0, 0))
>T : Symbol(T, Decl(destructureGenerics.ts, 0, 19))
>args : Symbol(args, Decl(destructureGenerics.ts, 0, 36))
>T : Symbol(T, Decl(destructureGenerics.ts, 0, 19))
>T : Symbol(T, Decl(destructureGenerics.ts, 0, 19))

var x = f(1,2);
>x : Symbol(x, Decl(destructureGenerics.ts, 1, 3), Decl(destructureGenerics.ts, 2, 3))
>f : Symbol(f, Decl(destructureGenerics.ts, 0, 0))

var x: [1, 2];
>x : Symbol(x, Decl(destructureGenerics.ts, 1, 3), Decl(destructureGenerics.ts, 2, 3))

declare function g<T extends [number, number]>(...args: T): T;
>g : Symbol(g, Decl(destructureGenerics.ts, 0, 0))
>g : Symbol(g, Decl(destructureGenerics.ts, 2, 14))
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
>args : Symbol(args, Decl(destructureGenerics.ts, 3, 47))
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))

// var y = g(1); // error
// var y: [1];
var z = g(1,2);
>z : Symbol(z, Decl(destructureGenerics.ts, 6, 3))
>g : Symbol(g, Decl(destructureGenerics.ts, 0, 0))
>z : Symbol(z, Decl(destructureGenerics.ts, 4, 3), Decl(destructureGenerics.ts, 5, 3))
>g : Symbol(g, Decl(destructureGenerics.ts, 2, 14))

var z: [1,2];
>z : Symbol(z, Decl(destructureGenerics.ts, 4, 3), Decl(destructureGenerics.ts, 5, 3))

// var z: [1,2];
// var a = g(1,2,3); // error
// var a: [1,2,3];
declare function h<T>(...args: T[]): T;
>h : Symbol(h, Decl(destructureGenerics.ts, 6, 15))
>T : Symbol(T, Decl(destructureGenerics.ts, 10, 19))
>args : Symbol(args, Decl(destructureGenerics.ts, 10, 22))
>T : Symbol(T, Decl(destructureGenerics.ts, 10, 19))
>T : Symbol(T, Decl(destructureGenerics.ts, 10, 19))
>h : Symbol(h, Decl(destructureGenerics.ts, 5, 13))
>T : Symbol(T, Decl(destructureGenerics.ts, 6, 19))
>args : Symbol(args, Decl(destructureGenerics.ts, 6, 22))
>T : Symbol(T, Decl(destructureGenerics.ts, 6, 19))
>T : Symbol(T, Decl(destructureGenerics.ts, 6, 19))

var b = h(1,2,3);
>b : Symbol(b, Decl(destructureGenerics.ts, 11, 3))
>h : Symbol(h, Decl(destructureGenerics.ts, 6, 15))
>b : Symbol(b, Decl(destructureGenerics.ts, 7, 3), Decl(destructureGenerics.ts, 8, 3))
>h : Symbol(h, Decl(destructureGenerics.ts, 5, 13))

// var b: 1|2|3;
var b: number;
>b : Symbol(b, Decl(destructureGenerics.ts, 7, 3), Decl(destructureGenerics.ts, 8, 3))

31 changes: 22 additions & 9 deletions tests/baselines/reference/destructureGenerics.types
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
=== tests/cases/compiler/destructureGenerics.ts ===
// declare function f<T extends any[]>(...args: T): T;
// var x = f(1,2);
// var x: number[];
declare function f<T extends any[]>(...args: T): T;
>f : <T extends any[]>(...args: T) => T
>T : T
>args : T
>T : T
>T : T

var x = f(1,2);
>x : [1, 2]
>f(1,2) : [1, 2]
>f : <T extends any[]>(...args: T) => T
>1 : 1
>2 : 2

var x: [1, 2];
>x : [1, 2]

declare function g<T extends [number, number]>(...args: T): T;
>g : <T extends [number, number]>(...args: T) => T
>T : T
>args : T
>T : T
>T : T

// var y = g(1); // error
// var y: [1];
var z = g(1,2);
>z : [1, 2]
>g(1,2) : [1, 2]
>g : <T extends [number, number]>(...args: T) => T
>1 : 1
>2 : 2

// var z: [1,2];
// var a = g(1,2,3); // error
// var a: [1,2,3];
var z: [1,2];
>z : [1, 2]

declare function h<T>(...args: T[]): T;
>h : <T>(...args: T[]) => T
>T : T
Expand All @@ -36,5 +48,6 @@ var b = h(1,2,3);
>2 : 2
>3 : 3

// var b: 1|2|3;
var b: number;
>b : number

15 changes: 15 additions & 0 deletions tests/baselines/reference/destructureGenericsErrors.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests/cases/compiler/destructureGenericsErrors.ts(2,9): error TS2554: Expected 2 arguments, but got 1.
tests/cases/compiler/destructureGenericsErrors.ts(4,15): error TS2345: Argument of type '3' is not assignable to parameter of type 'never'.


==== tests/cases/compiler/destructureGenericsErrors.ts (2 errors) ====
declare function g<T extends [number, number]>(...args: T): T;
var y = g(1); // error
~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
var y: [1];
var a = g(1,2,3); // error
~
!!! error TS2345: Argument of type '3' is not assignable to parameter of type 'never'.
var a: [1,2,3];

13 changes: 13 additions & 0 deletions tests/baselines/reference/destructureGenericsErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [destructureGenericsErrors.ts]
declare function g<T extends [number, number]>(...args: T): T;
var y = g(1); // error
var y: [1];
var a = g(1,2,3); // error
var a: [1,2,3];


//// [destructureGenericsErrors.js]
var y = g(1); // error
var y;
var a = g(1, 2, 3); // error
var a;
17 changes: 17 additions & 0 deletions tests/baselines/reference/destructureGenericsErrors.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/compiler/destructureGenericsErrors.ts ===
declare function g<T extends [number, number]>(...args: T): T;
>g : Symbol(g, Decl(destructureGenericsErrors.ts, 0, 0))
>T : Symbol(T, Decl(destructureGenericsErrors.ts, 0, 19))
>args : Symbol(args, Decl(destructureGenericsErrors.ts, 0, 47))
>T : Symbol(T, Decl(destructureGenericsErrors.ts, 0, 19))
>T : Symbol(T, Decl(destructureGenericsErrors.ts, 0, 19))

// var y = g(1); // error
// var y: [1];
var a = g(1,2,3); // error
>a : Symbol(a, Decl(destructureGenericsErrors.ts, 3, 3), Decl(destructureGenericsErrors.ts, 4, 3))
>g : Symbol(g, Decl(destructureGenericsErrors.ts, 0, 0))

var a: [1,2,3];
>a : Symbol(a, Decl(destructureGenericsErrors.ts, 3, 3), Decl(destructureGenericsErrors.ts, 4, 3))

21 changes: 21 additions & 0 deletions tests/baselines/reference/destructureGenericsErrors.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== tests/cases/compiler/destructureGenericsErrors.ts ===
declare function g<T extends [number, number]>(...args: T): T;
>g : <T extends [number, number]>(...args: T) => T
>T : T
>args : T
>T : T
>T : T

// var y = g(1); // error
// var y: [1];
var a = g(1,2,3); // error
>a : [1, 2, 3]
>g(1,2,3) : [1, 2, 3]
>g : <T extends [number, number]>(...args: T) => T
>1 : 1
>2 : 2
>3 : 3

var a: [1,2,3];
>a : [1, 2, 3]

9 changes: 8 additions & 1 deletion tests/baselines/reference/mappedTypeErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(77,59): error TS2345: A
Object literal may only specify known properties, and 'z' does not exist in type 'Readonly<{ x: number; y: number; }>'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(83,58): error TS2345: Argument of type '{ x: number; y: number; z: number; }' is not assignable to parameter of type 'Partial<{ x: number; y: number; }>'.
Object literal may only specify known properties, and 'z' does not exist in type 'Partial<{ x: number; y: number; }>'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(105,15): error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
Types of property 'a' are incompatible.
Type 'undefined' is not assignable to type 'string'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(106,17): error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, "a" | "b">'.
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(123,12): error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
Expand All @@ -46,7 +49,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,16): error TS2322:
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: Type 'P' cannot be used to index type 'T'.


==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (25 errors) ====
==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (26 errors) ====
interface Shape {
name: string;
width: number;
Expand Down Expand Up @@ -197,6 +200,10 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536:
setState(foo, { });
setState(foo, foo);
setState(foo, { a: undefined }); // Error
~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
!!! error TS2345: Types of property 'a' are incompatible.
!!! error TS2345: Type 'undefined' is not assignable to type 'string'.
setState(foo, { c: true }); // Error
~~~~~~~
!!! error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
Expand Down
Loading

0 comments on commit 9b6de0c

Please sign in to comment.