2016-12-23 22:31:38 +03:00
|
|
|
exports[`test scope.js 1`] = `
|
|
|
|
"function foo<X, Y:X>(x:X, y:Y):void { }
|
2016-12-30 19:56:42 +03:00
|
|
|
foo(0, \"\");
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
function bar<X:number, Y:X>(x:X, y:Y): number { return y*0; }
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-01-24 20:37:01 +03:00
|
|
|
function foo<X, Y: X>(x: X, y: Y): void {}
|
2016-12-30 19:56:42 +03:00
|
|
|
foo(0, \"\");
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
function bar<X: number, Y: X>(x: X, y: Y): number {
|
2016-12-28 05:40:04 +03:00
|
|
|
return y * 0;
|
2017-01-11 18:16:38 +03:00
|
|
|
}
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test test.js 1`] = `
|
|
|
|
"function foo<T: number>(x: T): T {
|
|
|
|
var _ = x * 1; // OK
|
|
|
|
var y: string = x; // error
|
|
|
|
return x; // OK
|
|
|
|
}
|
|
|
|
|
|
|
|
class C<T: number> {
|
|
|
|
bar<U: number>(x: U): T {
|
|
|
|
return x; // error, since T: number and U: number does not imply U: T
|
|
|
|
}
|
|
|
|
qux<U: T>(x: U): T {
|
|
|
|
var _ = x * 1; // OK, since T: number and U: T implies U: number
|
|
|
|
var y: string = x; // error
|
|
|
|
return x; // OK, since U: T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function example<T: {x: number}>(o: T): T { o.x = 0; return o; }
|
2016-12-30 19:56:42 +03:00
|
|
|
var obj1: {x: number; y: string} = example({x: 0, y: \"\"});
|
2016-12-23 22:31:38 +03:00
|
|
|
var obj2: {x: number} = example({x: 0});
|
|
|
|
|
|
|
|
var c: C<string> = new C; // error, since T = string is incompatible with number
|
|
|
|
var q: number = c.qux(0);
|
|
|
|
/* 2 more errors, since argument U = number is incompatible with T = string, and
|
|
|
|
* result T = string is incompatible with number */
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-27 21:29:31 +03:00
|
|
|
function foo<T: number>(x: T): T {
|
2017-01-26 22:57:43 +03:00
|
|
|
var _ = x * 1; // OK
|
|
|
|
var y: string = x; // error
|
2017-01-10 05:49:06 +03:00
|
|
|
return x; // OK
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
class C<T: number> {
|
|
|
|
bar<U: number>(x: U): T {
|
2017-01-10 05:49:06 +03:00
|
|
|
return x; // error, since T: number and U: number does not imply U: T
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
|
|
|
qux<U: T>(x: U): T {
|
2017-01-26 22:57:43 +03:00
|
|
|
var _ = x * 1; // OK, since T: number and U: T implies U: number
|
|
|
|
var y: string = x; // error
|
2017-01-10 05:49:06 +03:00
|
|
|
return x; // OK, since U: T
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
function example<T: { x: number }>(o: T): T {
|
2016-12-28 05:40:04 +03:00
|
|
|
o.x = 0;
|
2016-12-27 21:29:31 +03:00
|
|
|
return o;
|
|
|
|
}
|
2017-01-05 01:26:44 +03:00
|
|
|
var obj1: { x: number, y: string } = example({ x: 0, y: \"\" });
|
2016-12-28 05:40:04 +03:00
|
|
|
var obj2: { x: number } = example({ x: 0 });
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-26 22:57:43 +03:00
|
|
|
var c: C<string> = new C(); // error, since T = string is incompatible with number
|
2016-12-28 05:40:04 +03:00
|
|
|
var q: number = c.qux(0);
|
2017-01-10 05:49:06 +03:00
|
|
|
/* 2 more errors, since argument U = number is incompatible with T = string, and
|
2017-01-11 18:16:38 +03:00
|
|
|
* result T = string is incompatible with number */
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|