Skip to content

Nested defs with context bounds are desugared to nested defs with implicit parameters that have the same name #877

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
smarter opened this issue Oct 27, 2015 · 0 comments

Comments

@smarter
Copy link
Member

smarter commented Oct 27, 2015

class First[A]
class Second[A]

class Foo {
  def foo[A: First] = {
    def bar[B: Second] = {
      val fst: First[A] = implicitly[First[A]]
      val snd: Second[B] = implicitly[Second[B]]
    }
  }
}

is desugared to:

package <empty> {
  class First[A]() extends Object() { 
    type First$$A
    private[this] type A = First$$A
  }
  class Second[A]() extends Object() { 
    type Second$$A
    private[this] type A = Second$$A
  }
  class Foo() extends Object() { 
    def foo[A](implicit evidence$0: First[A]): Unit = {
      def bar[B](implicit evidence$0: Second[B]): Unit = {
        val fst: First[A] = implicitly[First[A]](evidence$0)
        val snd: Second[B] = implicitly[Second[B]](evidence$0)
        ()
      }
      ()
    }
  }
}

Which fails to compile because evidence$0 in bar shadows evidence$0 in foo, scalac avoids this by using different names for the desugared implicit parameters(in fact, it seems to never reuse the same name in a given compilation unit, even in different classes):

    def foo[A](implicit evidence$1: First[A]): Unit = {
      def bar[B](implicit evidence$2: Second[B]): Unit = {
        val fst: First[A] = scala.this.Predef.implicitly[First[A]](evidence$1);
        val snd: Second[B] = scala.this.Predef.implicitly[Second[B]](evidence$2);
        ()
      };
      ()
    }
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