Skip to content

Not all type parameters are substituted when checking function type parameter bound compatibility #29629

@stereotype441

Description

@stereotype441

The analyzer function FunctionTypeImpl.relateTypeFormals substitutes type bound inside the same loop that generates the substitution. This means that if one type variable refers to a later type variable, the later type variable won't get substituted when checking the bound for the former. E.g.:

relateTypeFormals(<T extends U, U>() => dynamic, <V extends W, W>() => dynamic)

would return false, since during the first loop iteration, it would only substitute fresh type variables for T and V, causing it to call relation(W, U).

What we should do instead is build up a full substitution of fresh type variables for all of the type variables in f1 and f2 first, and then check all the bounds.

This fix needs to be made in both analyzer and front_end (see TypeConstraintGatherer._matchTypeFormals).

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