assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Basic support for inner type aliases

Open CountBleck opened this issue 1 year ago • 3 comments

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

CountBleck avatar Jul 29 '22 10:07 CountBleck

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.

CountBleck avatar Jul 30 '22 07:07 CountBleck

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.

MaxGraey avatar Jul 31 '22 06:07 MaxGraey

This next commit should fix the aforementioned bug with ctxTypes.

CountBleck avatar Aug 01 '22 04:08 CountBleck

For now, I'm going to close this PR since I haven't been working on it.

CountBleck avatar Dec 22 '22 17:12 CountBleck