Skip to content

Commit

Permalink
Improve valueof definitions. Add some extra tests (AssemblyScript#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey authored Jul 28, 2022
1 parent 71b02d4 commit 24a908d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,9 @@ declare abstract class i31 {
/** Macro type evaluating to the underlying native WebAssembly type. */
declare type native<T> = T;
/** Special type evaluating the indexed access index type. */
declare type indexof<T extends unknown[]> = keyof T;
declare type indexof<T extends ArrayLike<unknown>> = keyof T;
/** Special type evaluating the indexed access value type. */
declare type valueof<T extends unknown[]> = T[0];
declare type valueof<T extends ArrayLike<unknown>> = T[0];
/** A special type evaluated to the return type of T if T is a callable function. */
declare type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
/** A special type evaluated to the return type of T if T is a callable function. */
Expand Down
17 changes: 17 additions & 0 deletions tests/compiler/indexof-valueof.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@
drop
i32.const 1
drop
i32.const 0
i32.eqz
drop
i32.const 4
i32.const 4
i32.eq
drop
i32.const 1
drop
i32.const 1
drop
i32.const 8
i32.const 8
i32.eq
drop
i32.const 1
drop
i32.const 1
drop
i32.const 1
Expand Down
6 changes: 6 additions & 0 deletions tests/compiler/indexof-valueof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ assert(sizeof<indexof<Float32Array>>() == 4); // i32
assert(isInteger<valueof<Uint8ClampedArray>>());
assert(!isSigned<valueof<Uint8ClampedArray>>());
assert(sizeof<valueof<Uint8ClampedArray>>() == 1);
assert(isFloat<valueof<Float32Array>>());
assert(!isInteger<valueof<Float32Array>>());
assert(sizeof<valueof<Float32Array>>() == 4);
assert(isInteger<valueof<Int64Array>>());
assert(isSigned<valueof<Int64Array>>());
assert(sizeof<valueof<Int64Array>>() == 8);

// map indexes
assert(isInteger<indexof<Map<i32,i32>>>());
Expand Down

0 comments on commit 24a908d

Please sign in to comment.