mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 00:11:28 +00:00
Implement optional type parameters (#360)
* Add a NATIVE<T> macro type to simplify use of a native WebAssembly type * Add default type parameters for internal helpers for explicit loads and stores * Unify loadUnsafe/loadUnsafeWithOffset etc. into one * Renamed loadUnsafe etc. into just LOAD, like a macro * Implement parsing of index signatures, but ignore them, for properly linting code * Refactor TypedArray<T> to use macros
This commit is contained in:
28
tests/compiler/optional-typeparameters.ts
Normal file
28
tests/compiler/optional-typeparameters.ts
Normal file
@ -0,0 +1,28 @@
|
||||
function testConcrete<T,U = i32>(a: T): U {
|
||||
return a;
|
||||
}
|
||||
|
||||
function testDerived<T,U = T>(a: T): U {
|
||||
return a;
|
||||
}
|
||||
|
||||
testConcrete<i32>(1);
|
||||
testDerived<i32>(2);
|
||||
|
||||
class TestConcrete<T,U = i32> {
|
||||
test<V = i32>(a: T, b: U): V {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
|
||||
class TestDerived<T,U = T> {
|
||||
test<V = U>(a: T, b: U): V {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
|
||||
import "allocator/arena";
|
||||
var tConcrete = new TestConcrete<i32>();
|
||||
tConcrete.test<i32>(1, 2);
|
||||
var tDerived = new TestDerived<f64>()
|
||||
tDerived.test<f64>(1, 2);
|
Reference in New Issue
Block a user