Higher order generic function called on a generic function breaks generic inference
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Here is a minimal bug representation. For me it is a surprise that `id(id)` returns a function of type `(T) => T` while just a bit more complex `idFn(id)` returns a function of type `empty => empty`. Sure, when the latter gets applied to an argument of a defined type it get's it's type inferred to, say, `number => number` in case of `f2(123)`. But this is not how you'd expect a second level generic to work. Or I'm missing something huge here? 😅
```js
function id(x: T): T {
return x
}
function idFn(x: A => B): A => B {
return x
}
// this works fine
const f1 = id(id)
f1(123).toFixed()
f1("123").concat()
// this looses it's generic nature :(
const f2 = idFn(id)
f2(123).toFixed()
f2("123").concat()
```
[flow.org/try](https://flow.org/try/#0GYVwdgxgLglg9mABDAJgHgCoD4AUAPALkQwEoiNEBvAKETsQCcBTKEBpPagX2utElgJkKAGJg0AQQA0iAEK5CiCYgC8WOWSWr1sqrXrNW7RJx7UA9OcRQAFjADOiAO5wGAa0fAYYJtQgJ7KERgAEZVYRxUEj4QnBCAJgBmEgA6KDgRGDwmFBxo0JwAIgTEwtT-SABDKDzeS2s7RwAbODh7JkcYKAByRwBzJh8GGAhEMGq2JkQCHD8AoOB48NQxSJR8+Lik1PTM7NyNopKylIqIatrqIA)
Contributor guide
Assessment
This issue has not been assessed yet.