assemblyscript
assemblyscript copied to clipboard
Basic support for inner type aliases
This PR is an attempt at #2392. This is a basic implementation, with features missing like:
- Declaration hoisting: currently, inner type aliases can only be used after their declaration.
- ~~Parameter types: these are ignored by the implementation, leading them to be treated as if they were never defined.~~
However, these inner type declarations are block-scoped, thanks to a modification of Flow
.
- [x] I've read the contributing guidelines
- [x] I've added my name and email to the NOTICE file
ctxTypes.clear();
on line 722 in resolver.ts
causes a bug, it seems. If it's removed, code like this compiles:
export function bar<T>(): void {
type Dummy = Set<u8>;
type WorkingA = T; // works
type WorkingB = Array<T>; // works
type WorkingC = Dummy; // works
type FailingA<X> = T; // fails
type FailingB<X> = Array<T>; // fails
type FailingC<X> = Dummy; // fails
type FailingD<X> = Map<X, T>; // fails
const a: Dummy | null = null;
const b: WorkingA | null = null;
const c: WorkingB | null = null;
const d: WorkingC | null = null;
const e: FailingA<i32> | null = null;
const f: FailingB<i32> | null = null;
const g: FailingC<i32> | null = null;
const h: FailingD<i32> | null = null;
}
export function add(a: i32, b: i32): i32 {
bar<Set<usize>>();
return a + b;
}
I didn't remove it, because I didn't know what it was for, and there's probably something wrong with what I'm doing.
type FailingA<X> = T; // fails
type FailingB<X> = Array<T>; // fails
type FailingC<X> = Dummy; // fails
type FailingD<X> = Map<X, T>; // fails
All these cases should be compiled without errors. FailingA
, FailingB
, FailingC
may produce warning about unused param X
but it still corrects.
This next commit should fix the aforementioned bug with ctxTypes
.
For now, I'm going to close this PR since I haven't been working on it.