Skip to content

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

Open
@turbolent

Description

@turbolent

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions