Skip to content

fix: infer return type in implicit return arrow function #2433

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

Merged

Conversation

HerrCai0907
Copy link
Member

It makes resolveFunctionExpression can return correct function type for expression like (x: i32) => x

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@HerrCai0907 HerrCai0907 force-pushed the fix/infer-arrow-function-return-type branch from da99ace to 142aa71 Compare August 12, 2022 06:48
@MaxGraey
Copy link
Member

MaxGraey commented Aug 12, 2022

Nice! Please add tests for this feature. Or modify existing tests. For example from:
https://github.com/AssemblyScript/assemblyscript/blob/main/tests/compiler/std/array.ts#L783

let newArr = arr.map<f32>((value: i32) => <f32>value);

to

let newArr = arr.map((value: i32) => <f32>value);
// or
// let newArr = arr.map(value => <f32>value);

Co-authored-by: dcode <dcode@dcode.io>
@MaxGraey MaxGraey merged commit f7beaac into AssemblyScript:main Aug 21, 2022
@MaxGraey
Copy link
Member

Thanks!

@HerrCai0907 HerrCai0907 deleted the fix/infer-arrow-function-return-type branch August 21, 2022 01:57
@MaxGraey
Copy link
Member

MaxGraey commented Aug 21, 2022

Btw this works properly now:

export function test(arr: i32[]): f32[] {
  return arr.map((x: i32) => <f32>x);
}

but that one still required explicit type arg for map:

export function test(arr: i32[]): f32[] {
  return arr.map(x => <f32>x); // ERROR TS1140: Type argument expected.
}

also:

export function test(arr: i32[]): string[] {
  return arr.map((x: i32) => x.toString()); // ERROR TS1140: Type argument expected.
}

Will be great to fix such more usual case as well if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants