Skip to content

Placeholder syntax for anonymous functions chooses too narrow a scope for _: T #903

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
retronym opened this issue Nov 2, 2015 · 0 comments

Comments

@retronym
Copy link
Member

retronym commented Nov 2, 2015

This program compiles with scalac:

object Test {
  def contains(s: String, i: Int) = true
  def test1 = {
    val f = contains("", (_: Int)) // dotc:
    f.apply(0)
    //     sandbox/eta.scala:4: error: type mismatch:
    //  found   : Int => Int
    //  required: Int
    //     val f = contains("", (_: Int))
    //                          ^
    // sandbox/eta.scala:5: error: apply is not a member of Boolean(f)
    //     f.apply(0)
    //      ^
  }

  def test2 = {
    val f = "".contains("", (_: Int)) // dotc:
    f.apply(0)
    // sandbox/eta.scala:18: error: apply is not a member of Boolean(f)
    //     f.apply(0)
    //       ^
  }
}

But with dotty, if tails with the compile errors inlined in comments above. Here's the post-typer AST:

package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends Object() { this: Test.type =>
    def contains(s: String, i: Int): Boolean = true
    def test1: <error> = {
      val f: Boolean =
        Test.contains("", {
          def $anonfun(_$1: Int): Int = _$1: Int
          closure($anonfun)
        })
      f.apply(0)
    }
    def test2: <error> = {
      val f: Boolean =
        augmentString("").contains[Any'](
          Tuple2.apply[String', (Int => Int)']("", {
            def $anonfun(_$2: Int): Int = _$2: Int
            closure($anonfun)
          })
        )
      f.apply(0)
    }
  }
}

Tested with edfb6e7

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

2 participants