Scala Programming Language
  1. Scala Programming Language
  2. SI-7815

Eta-expansion too conservative wrt dependent method type

    Details

      Description

      Consider this snippet:

      trait Foo[A] {
        type Repr
        def f(a: A): Repr
      }
       
      object Foo {
        type Aux[A, B] = Foo[A] { type Repr = B }
      }
       
      object Main extends App {
        def mapWithFoo[A, B](as: List[A])(implicit foo: Foo.Aux[A, B]) =
          as map foo.f
      }
      

      scalac complains about that it can't convert the method to a function value, because it deems it to have a dependent type. At first glance, that seems correct. However, the following works:

        def mapWithFoo[A, B](as: List[A])(implicit foo: Foo.Aux[A, B]) =
          as map (a => foo.f(a))
      

      As you can see, the "dependent" return type `Repr` is actually bound to `B`, so eta-expansion could be done.

      Use case: shapeless 2.0.0-M1. Previously, the `FooAux` types were proper traits, so no dependent types involved. Now, they are type aliases in the style of `Foo.Aux`.

      Related to SI-4751.

        Activity

        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2919

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Lars Hupel
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development