Method overloading fails to resolve to correct method
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
I have an overloaded method that has two distinct signatures. One signature is a generic that returns the invoked argument (e.g. returns some element in an encapsulation container). If I construct a type that is a union of this generic type (e.g. `Encapsulator | Encapsulator`), I see some odd behavior. If I removed the un-used overloaded method signature, there are no errors.
---
Simplified example on [flow.org/try](https://flow.org/try/#0C4TwDgpgBAogdgYwIZgM4FcA2TgHsBOAPACoB8UAvFAN4BQUUAFAJQBcUxtAvgNy0Bm6RMACWuOFAiIUGbMAgliueMjRYcEUo1wAjAFbtiSlTPXy2saWrkFFyq7I3k6DfBGDp8ElpXK69fFy0tKCQsAAewPhICMAASu6ecMTg0FSEAGpaPhTkGcy+UBl8tAAmEAjYblCVSKioUAAiEFKqjnj4NPRQYPi4AG4i5STsJtY4tgBUpFqtpnIQpYYWACQAwkiYmIQwkdGxCR5eKZAANBykp929A0MQjHDoALbsj086EPgWbx-43MEIcSoYBQERwYFIRBpKBwCAAdyaLQcZgILBKoWgY3aiwA8vgAHLPX6USxtFFEYH4MEAc3IAB9SfMJkQfp9SHxAeCQXCABa4ADScFwcNQo2RC1KeMJ70+JMY1C47EhIGYHKBIMpNKlRNlVDBEKhADoboNyoxeQKhSLVUA). Remove line 12 and type checking succeeds.
```
type Encapsulator = {
(): T
};
function encapsulate(obj: TToEncapsulate): Encapsulator {
return () => obj;
}
type ExtractReturnType = (() => V) => V;
declare class Deencapsulator {
provide>(encapsulated: T): $Call,
provide(num: number): number
}
const instance = new Deencapsulator();
type EncapsulatedOrNumber = Encapsulator | Encapsulator;
const whoKnows: EncapsulatedOrNumber = ({}: any);
const stringOrNumber = instance.provide(whoKnows);
```
Yields the following error:
```
19: const stringOrNumber = instance.provide(whoKnows);
^ Cannot call `instance.provide` because number [1] is incompatible with string [2] in type argument `T` [3] of type argument `T`.
References:
17: type EncapsulatedOrNumber = Encapsulator | Encapsulator;
^ [1]
17: type EncapsulatedOrNumber = Encapsulator | Encapsulator;
^ [2]
1: type Encapsulator = {
^ [3]
```
Commenting out `provide(num: number): number` yields no errors.
Contributor guide
Assessment
This issue has not been assessed yet.