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

Infer type arguments when type parameter is used as return type #3712

Open
Tracked by #3611
turbolent opened this issue Dec 10, 2024 · 0 comments
Open
Tracked by #3611

Infer type arguments when type parameter is used as return type #3712

turbolent opened this issue Dec 10, 2024 · 0 comments

Comments

@turbolent
Copy link
Member

Issue to be solved

Generic functions which have a type parameter that is not used in an argument, but is used in a return type, should have their type argument inferred when an expected type is given.

For example, given a generic function

fun foo<T>() -> T { /* ... */ }

Then an invocation with an expected type should succeed, inferring the type parameter T to Bool:

let x: Bool = foo()

However, in an invocation without an expected type, the type argument cannot be inferred and an explicit type argument is necessary:

let x = foo<Bool>()

Suggested Solution

If an expected type is provided for an invocation, infer the type arguments based on the return type (if any).

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

No branches or pull requests

1 participant