Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type inference for functions like fold #18780

Merged
merged 4 commits into from
Nov 14, 2023

Commits on Nov 13, 2023

  1. Improve type inference for functions like fold

    When calling a fold with an accumulator like `Nil` or `List()` one used to have add
    an explicit type ascription. This is now no longer necessary. When instantiating
    type variables that occur invariantly in the expected type of a lambda, we now replace
    covariant occurrences of `Nothing` in the (possibly widened) type of the accumulator
    with fresh type variables.
    
    The idea is that a fresh type variable in such places is always better than Nothing. For
    module values such as `Nil` we widen to `List[<fresh var>]`. This does possibly cause a new
    type error if the fold really wanted a `Nil` instance. But that case seems very rare,
    so it looks like a good bet in general to do the widening.
    odersky committed Nov 13, 2023
    Configuration menu
    Copy the full SHA
    6c556aa View commit details
    Browse the repository at this point in the history
  2. Address review comments

    odersky committed Nov 13, 2023
    Configuration menu
    Copy the full SHA
    21f542b View commit details
    Browse the repository at this point in the history
  3. Put back test in instantiate

    odersky committed Nov 13, 2023
    Configuration menu
    Copy the full SHA
    18cf1b4 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6f1a09a View commit details
    Browse the repository at this point in the history