Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve valueof definitions. Add some extra tests #2390

Merged
merged 4 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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