Skip to content
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

assertion failed: private method dynamicPower in object X #8208

Closed
unkarjedy opened this issue Feb 5, 2020 · 0 comments · Fixed by #13188
Closed

assertion failed: private method dynamicPower in object X #8208

unkarjedy opened this issue Feb 5, 2020 · 0 comments · Fixed by #13188

Comments

@unkarjedy
Copy link
Contributor

minimized code

package playground

import scala.quoted._
import scala.quoted.matching._

object X {

  inline def power(n: Int, x: Double): Double =
    ${ powerImpl('n, 'x) }

  private def powerImpl(nExpr: Expr[Int], xExpr: Expr[Double])(given QuoteContext): Expr[Double] =
    nExpr match {
      case Const(n1) => '{ 42.0 }
      case _ => '{ dynamicPower($nExpr, $xExpr) }
    }

  private def dynamicPower(n: Int, x: Double): Double = {
    println(s"dynamic: $n^$x")
    if (n == 0) 1.0
    else if (n % 2 == 0) dynamicPower(n / 2, x * x)
    else x * dynamicPower(n - 1, x)
  }
}

create some worksheet:

import playground.X
X.power(f, 2)

Compilation output

Exception in thread "main" java.lang.AssertionError: assertion failed: private method dynamicPower in object X in C:\Users\dmitrii.naumenko\Desktop\dev\dotty-example-project\src\main\scala\playground\X.scala accessed from constructor rs$line$10$ in rs$line$10
    at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
    at dotty.tools.dotc.transform.ExpandPrivate.ensurePrivateAccessible(ExpandPrivate.scala:84)
    at dotty.tools.dotc.transform.ExpandPrivate.transformIdent(ExpandPrivate.scala:92)
    at dotty.tools.dotc.transform.ExpandPrivate.transformIdent(ExpandPrivate.scala:91)
    at dotty.tools.dotc.transform.MegaPhase.goIdent(MegaPhase.scala:551)
    at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:225)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:270)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:306)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:287)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:324)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:406)
    at dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
    at scala.collection.immutable.List.mapConserve(List.scala:444)
    at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:286)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:245)
    at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:248)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
    at dotty.tools.dotc.transform.MegaPhase.transformSpecificTree(MegaPhase.scala:400)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:336)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
    at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:404)
    at dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
    at scala.collection.immutable.List.mapConserve(List.scala:444)
    at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
    at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:356)
    at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
    at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
    at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:415)
    at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:427)
    at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:315)
    at scala.collection.immutable.List.map(List.scala:219)
    at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:316)
    at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:161)
    at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
    at dotty.tools.dotc.Run.runPhases$5(Run.scala:171)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:179)
    at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
    at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:186)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:128)
    at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:156)
    at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:166)
    at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:229)
    at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
    at dotty.tools.repl.ReplDriver.run$$anonfun$1(ReplDriver.scala:136)
    at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
    at dotty.tools.repl.ReplDriver.run(ReplDriver.scala:137)
    at dotty.tools.languageserver.worksheet.ReplProcess$.main(ReplProcess.scala:13)
    at dotty.tools.languageserver.worksheet.ReplProcess.main(ReplProcess.scala)

expectation

X.power shouldn't compile cause it is inlined and uses private method

@dottybot dottybot added this to Unassigned in Spree Mar 22, 2021
@MaximeKjaer MaximeKjaer moved this from Unassigned to Assigned in Spree Jun 8, 2021
@MaximeKjaer MaximeKjaer moved this from Assigned to Unassigned in Spree Jun 8, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 28, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 28, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 29, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 30, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 2, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
tanishiking pushed a commit to tanishiking/scala3 that referenced this issue Aug 10, 2021
This adds inline accessors for private/protected members if needed as we do with inline defs.

Fixes scala#8208
Fixes scala#12948
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Spree
Unassigned
Development

Successfully merging a pull request may close this issue.

3 participants