Skip to content
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

Type inference for constructors #681

Open
1 of 3 tasks
degory opened this issue Dec 29, 2020 · 0 comments
Open
1 of 3 tasks

Type inference for constructors #681

degory opened this issue Dec 29, 2020 · 0 comments
Assignees

Comments

@degory
Copy link
Owner

degory commented Dec 29, 2020

There are a number of scenarios where the actual type arguments of a type being instantiated can potentially be inferred from context:

  • Direct assignment of the result of a new expression to a variable or property with an explicit type
  • Directly passing the result of a new expression to a function as an actual argument
  • Instantiating a type via new where all of the formal type arguments can be pattern matched to corresponding types in actual constructor arguments

The first two cases are instances of the same kind of type inference needed to infer anonymous function argument types (see #498) - i.e. the inference is pushed from the outside down/from left to right into an expression rather than going from the inside out/right to left. It may be that a mechanism built to support #498 could also support these kinds of constructor type inference.

The last case is similar to generic argument type inference for function calls (see #679) - i.e. really just an extension of function overload resolution, although the results would need to be translated into what type to instantiate rather than what method signature to call.

@degory degory self-assigned this Dec 29, 2020
degory added a commit that referenced this issue Apr 15, 2024
Enhancements:
- Generic argument type inference for constructors (see #681)
- Generic argument type inference for static method calls
degory added a commit that referenced this issue Apr 15, 2024
Enhancements:
- Generic argument type inference for constructors (see #681)
- Generic argument type inference for static method calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant