Skip to content

Inlined parameter name conflict #9342

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
edolgy opened this issue Jul 10, 2020 · 2 comments · Fixed by #9379
Closed

Inlined parameter name conflict #9342

edolgy opened this issue Jul 10, 2020 · 2 comments · Fixed by #9379

Comments

@edolgy
Copy link

edolgy commented Jul 10, 2020

trait Label[A]:
  def apply(v: A): String

given [A] as Label[A] = _.toString

extension [A](x: A) inline def label(using inline l: Label[A]): String = l(x)

def label1[A](v: A) = v.label  // Compiles fine

def label2[A](l: A) = l.label  // Fails to compile because parameter `l` matches implicit argument name `l`
@nicolasstucki
Copy link
Contributor

Similar, but fails an assertion

trait Label[A]:
  def apply(v: A): String

def g[A]: Label[A] = _.toString

inline def label[A](x: A, inline l: Label[A]): String = l(x)

def label1[A](v: A) = label(v, g)  // Compiles fine
def label2[A](l: A) = label(l, g)  // Fails to compile because parameter `l` matches implicit argument name `l`
java.lang.AssertionError: assertion failed: Select(TypedSplice(Typed(Inlined(EmptyTree,List(),TypeApply(Ident(g),List(TypeTree[TypeRef(NoPrefix,type A)]))),TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),trait Label),List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)))])),apply) while compiling Foo.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: Select(TypedSplice(Typed(Inlined(EmptyTree,List(),TypeApply(Ident(g),List(TypeTree[TypeRef(NoPrefix,type A)]))),TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),trait Label),List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)))])),apply)
        at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
        at dotty.tools.dotc.typer.Inliner$InlineTyper.typedSelect(Inliner.scala:1198)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2388)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2478)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2548)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2549)
        at dotty.tools.dotc.typer.Typer.op$4$$anonfun$1(Typer.scala:2832)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2674)
        at dotty.tools.dotc.typer.Typer.op$2(Typer.scala:2834)
        at dotty.tools.dotc.typer.Typer.tryInsertImplicitOnQualifier(Typer.scala:2837)
        at dotty.tools.dotc.typer.Applications.tryWithImplicitOnQualifier$4(Applications.scala:904)
        at dotty.tools.dotc.typer.Applications.realApply$8$$anonfun$7(Applications.scala:958)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2677)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:961)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:999)
        ...

@nicolasstucki nicolasstucki self-assigned this Jul 10, 2020
@nicolasstucki
Copy link
Contributor

Minimized

inline def label(x: Int, inline g: Int => String): String = g(x)
def f: Int => String = ???
def label2(g: Int) = label(g, f)
def label2(g: Int): String = 
      {
        {
          f
        }.apply(
          {
            f // should be `g`
          }
        ):String
      }

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 16, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 16, 2020
@nicolasstucki nicolasstucki linked a pull request Jul 16, 2020 that will close this issue
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 17, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 17, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 29, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 10, 2020
nicolasstucki added a commit that referenced this issue Aug 10, 2020
Fix #9342: Use semantic name for inline bindings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants