Skip to content

AssertionError: asTerm called on not-at-Term val when using local methods inside a by-name closure in super-class constructor parameter #8846

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
neko-kai opened this issue Apr 30, 2020 · 0 comments · Fixed by #8851

Comments

@neko-kai
Copy link
Contributor

neko-kai commented Apr 30, 2020

Minimized code

Related bug in scalac: scala/bug#11969

package example

class X(a: => Any)

class XImpl(
  param: Int
) extends X({
    def helper(): AutoCloseable = new AutoCloseable {
      def close() = println(param)
    }
    helper()
  })

Output

java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:532)
	at dotty.tools.dotc.transform.ExplicitOuter$.dotty$tools$dotc$transform$ExplicitOuter$$$outerParamAccessor(ExplicitOuter.scala:222)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:405)
	at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:413)
	at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:721)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2346)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:640)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2315)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
	at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$4(Erasure.scala:765)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.zipWithConserve$extension(Decorators.scala:110)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:765)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2345)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1867)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:866)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2322)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2003)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2333)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2337)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:849)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:853)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2353)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1867)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:866)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2322)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:849)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:853)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2353)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1867)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:866)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2322)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:849)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:853)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2353)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1867)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:866)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2322)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2003)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2333)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2337)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2403)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2522)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:953)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2129)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2376)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2404)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2443)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2455)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2566)
	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:121)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:318)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:319)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:165)
	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:175)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:183)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:190)
	at dotty.tools.dotc.Run.compileSources(Run.scala:127)
	at dotty.tools.dotc.Run.compile(Run.scala:110)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
	at dotty.tools.dotc.Driver.process(Driver.scala:194)
	at dotty.tools.dotc.Main.process(Main.scala)
	at xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:69)
	at xsbt.CompilerInterface.run(CompilerInterface.java:41)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:248)
	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:122)
	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:95)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:91)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:186)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3$adapted(MixedAnalyzingCompiler.scala:77)
	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:215)
	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:77)
	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:146)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:343)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:343)
	at sbt.internal.inc.Incremental$.doCompile(Incremental.scala:120)
	at sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:100)
	at sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:180)
	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:98)
	at sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:102)
	at sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:155)
	at sbt.internal.inc.Incremental$.compile(Incremental.scala:92)
	at sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:75)
	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:348)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:301)
	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:168)
	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:248)
	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:74)
	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:1765)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:1738)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
	at sbt.std.Transform$$anon$4.work(Transform.scala:67)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
	at sbt.Execute.work(Execute.scala:290)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Expectation

In Scalac this bug can be worked around by wrapping the block with ().pipe {_ => ... }, however, this doesn't help in dotty: https://scastie.scala-lang.org/mpRzPhuEQCun8oJTFEu8Pw

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.

1 participant