Skip to content

support multi-step bidirectional type inference #1211

@KotlinIsland

Description

@KotlinIsland

Summary

def f1() -> list[object]:
    return [1, 2, 3]  # lovely, bidirectional type inference uses the return type to infer `list[object]`

def f2() -> list[object]:
    result = [1, 2, 3]
    return result  # error: bi-directional type inference does not look ahead, so the inferred type is `list[int]`

note that there are two issues preventing the actual error from surfacing:

  • return position is not taken into account for constraint solving
  • [1, 2, 3] is inferred as list[Unknown | int], which is assignable to list[object]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bidirectional inferenceInference of types that takes into account the context of a declared type or expected typegenericsBugs or features relating to ty's generics implementationwishNot on the current roadmap; maybe in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions