Skip to content

Eta expansion difference to scalac #2009

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

Closed
felixmulder opened this issue Feb 20, 2017 · 2 comments
Closed

Eta expansion difference to scalac #2009

felixmulder opened this issue Feb 20, 2017 · 2 comments

Comments

@felixmulder
Copy link
Contributor

Scalac is happy to compile the code below:

object Test {

  trait Gen[T] {
    def map[U](f: T => U): Gen[U] = ???
  }

  def f[T](implicit g: Gen[T]): Gen[() => T] =
    g map ( () => _ )
}

whereas dotty fails with:

-- Error: local/func0.scala ----------------------------------------------------
8 |    g map ( () => _ )
  |                  ^
  |    missing parameter type for parameter _$1, expected = Test.Gen[() => T]
@smarter
Copy link
Member

smarter commented Feb 21, 2017

dotty parser:

def f[T](implicit g: Gen[T]): Gen[() => T] =
  _$1 => g map (() => _$1)

scalac parser:

def f[T](implicit g: Gen[T]): Gen[_root_.scala.Function0[T]] =
  g.map(((x$1) => (() => x$1)))

Honestly, I would expect this to expand to () => (x => x) but apparently both parsers disagree with me ;)

odersky added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2017
Logic was missing placeholders in rhs of lambdas.
@odersky
Copy link
Contributor

odersky commented Feb 22, 2017

@smarter Well spotted! I agree with scalacs parser here 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants