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

TastyInspector crashes when creating a TypeRepr of non-primitive type #13919

Closed
jodersky opened this issue Nov 10, 2021 · 0 comments · Fixed by #13953
Closed

TastyInspector crashes when creating a TypeRepr of non-primitive type #13919

jodersky opened this issue Nov 10, 2021 · 0 comments · Fixed by #13953
Assignees
Labels
area:tasty-inspector issues relating to the TASTy inspector itype:bug itype:crash

Comments

@jodersky
Copy link
Contributor

jodersky commented Nov 10, 2021

Compiler version

3.0.2, 3.1.0 and 3.1.1-RC1

Seems to be ok on 3.0.0

Minimized code

import scala.quoted.Quotes
import scala.tasty.inspector as ins
import scala.tasty.inspector.TastyInspector

class Traverser() extends ins.Inspector {

  def inspect(using q: Quotes)(tastys: List[ins.Tasty[q.type]]): Unit = {
    import q.reflect._

    TypeRepr.of[Int] // ok

    TypeRepr.of[String] // fail
    // java.util.NoSuchElementException: None.get while compiling out/app/jar/dest/out.jar
    // Exception in thread "main" java.util.NoSuchElementException: None.get
    //     at scala.None$.get(Option.scala:627)
    //     at scala.None$.get(Option.scala:626)
    //     at dotty.tools.dotc.quoted.QuotesCache$.getTree(QuotesCache.scala:19)
    //     at dotty.tools.dotc.quoted.PickledQuotes$.unpickle(PickledQuotes.scala:183)
    //     at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTypeTree(PickledQuotes.scala:66)
    //     at scala.quoted.runtime.impl.QuotesImpl.unpickleType(QuotesImpl.scala:2975)
    //     at Traverser.inspect(main.scala:11)
    //     at scala.tasty.inspector.TastyInspector$TastyInspectorPhase$1.runOn(TastyInspector.scala:73)
    //     at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
    //     at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    //     at scala.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:272)
    //     at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
    //     at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    //     at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
    //     at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
    //     at dotty.tools.dotc.Run.compileUnits(Run.scala:228)
    //     at dotty.tools.dotc.fromtasty.TASTYRun.compile(TASTYRun.scala:12)
    //     at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
    //     at dotty.tools.dotc.Driver.process(Driver.scala:199)
    //     at dotty.tools.dotc.Driver.process(Driver.scala:167)
    //     at dotty.tools.dotc.Driver.process(Driver.scala:179)
    //     at scala.tasty.inspector.TastyInspector$.inspectFiles(TastyInspector.scala:112)
    //     at scala.tasty.inspector.TastyInspector$.inspectAllTastyFiles(TastyInspector.scala:58)
    //     at main$package$.main(main.scala:32)
    //     at main.main(main.scala:25)
  }

}

@main() def main() = {

  val inspector = Traverser()
  scala.tasty.inspector.TastyInspector.inspectAllTastyFiles(
    Nil,
    "out/app/jar/dest/out.jar" :: Nil, // this is the jar of this program. Although we're not actually doing anything, we need to pass in at least one file, otherwise the bug does not manifest itself
    Nil
  )(inspector)

}

Mill build config

// install mill:
// curl -sS -L "https://github.com/com-lihaoyi/mill/releases/download/0.9.9/0.9.9" > mill && chmod +x mill

import mill._, scalalib._

object app extends ScalaModule {
  def scalaVersion = "3.1.0"
  def ivyDeps = Agg(
    ivy"org.scala-lang::scala3-tasty-inspector:${scalaVersion()}"
  )
}

Run mill app.jar && mill app in order to compile and run the program.

You can also get the fully working example here: https://github.com/jodersky/tasty-inspector-typerepr

Output (click arrow to expand)

The error as shown in the comment in the snippet above

@jodersky jodersky changed the title TastyInspector crashes when creating a TypeRepr TastyInspector crashes when creating a TypeRepr of non-primitive type Nov 10, 2021
@KacperFKorban KacperFKorban added the area:tasty-inspector issues relating to the TASTy inspector label Nov 10, 2021
jodersky pushed a commit to jodersky/dotty that referenced this issue Nov 15, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:tasty-inspector issues relating to the TASTy inspector itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants