kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.3k stars 42 forks source link

Expected type during value synthesis #74

Closed kaleidawave closed 6 months ago

kaleidawave commented 8 months ago

Currently the mapper functions a parameter is synthesised as generic

declare const array1: Array<number>;
array1.map(function mapper(a) { return a + 2 })

then the function is checked based on the restriction.

A better way would be to synthesise the function with the knowledge/expectation that it is expected to be a function as number => U. This means that the new_function can then create parameter restrictions eagerly.

This could be considered as traditional type inference

kaleidawave commented 6 months ago

Added the parameter-argument part with

https://github.com/kaleidawave/ezno/blob/1aa77e2aabb9533fb4fe90fa1ac9aaa24136256b/checker/src/types/calling.rs#L53-L98

Not great position + overhead of clone. But works ATM

These work though

image

from