forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall-inferred.ts
46 lines (36 loc) · 838 Bytes
/
call-inferred.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function foo<T>(a: T): T {
return a;
}
assert(foo(42) == 42);
assert(foo(42.0) == 42);
assert(foo(<f32>42.0) == 42);
function bar<T>(a: T = <f32>42.0): T {
return a;
}
assert(bar() == 42);
class Foo<T> {
constructor(public value: T) {}
static create<T>(value: T): Foo<T> {
return new Foo(value);
}
}
assert(new Foo(42).value == 42);
assert(Foo.create(42).value == 42);
class Bar {
doSomething<T>(a: T): T {
return a;
}
}
assert(new Bar().doSomething(42) == 42);
class Baz<T> extends Foo<T> {}
assert(new Baz(42).value == 42);
// TODO: this'd require return type inference, i.e., omitted return type
// function baz<T>(a: i32): T {
// return a;
// }
// baz(42);
// TODO: this'd ideally be inferred by matching contextualType, avoiding conversions
// function baz<T>(): T {
// return 1;
// }
// baz(42);