Skip to content

Call expression type context should affect function argument inference #1356

@ibraheemdev

Description

@ibraheemdev

Currently, the only type context we have access to when inferring function arguments is the annotated parameter type. However, the call expression annotation is also relevant, e.g.,

def id[T](x: T) -> T:
    return x

def _(i: int):
    x: list[int | None] = id([i])
    reveal_type(x)   # revealed (main): list[int | None] | list[Unknown | int] 

The problem is that we currently infer function arguments before the specializing the function call, and so the type context when inferring the list expression is still a typevar. On the other hand, we use the inferred argument types to infer the specialization, so there's a bit of a circular dependency here.

Metadata

Metadata

Assignees

Labels

bidirectional inferenceInference of types that takes into account the context of a declared type or expected type

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions