Skip to content

Revisit widening of nesting level of type variables  #15884

Closed
@odersky

Description

@odersky

Compiler Version

3.2.1.-RC1

Issue

When instantiating type variables in #15746, any type variable B in the instance type of a type variable A that is nested deeper than the current context needs to be instantiated itself. If B occurs invariantly in the instance type of A this is awkward since instantiating type variables to one of their bounds loses possibilities. So we do not instantiate B and lower the nesting level of B to the nesting level of the current context instead. The problem is that this trick does not play well with the backtracking of typerstates. As stated in the comment of class NeedsLeveling in ConstraintHandling:

            // TODO: This widening is a side effect that is not undone if a typer state is aborted
            // I don't think it's a soundness problem, since all that could happen is that
            // the type variable causes earlier instantiations of other type variables
            // down the line. But it could produce a hard-to-debug side effect that leads
            // to worse types than expected. We should find a more robust way to do this.
            // Maybe instantiating `tp` to another freshly created type at nesting level?

We should act on the TODO and find a better way to treat invariantly occurring nested type variables.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions