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

Pattern matching on quoted.Type crashes #284

Closed
matil019 opened this issue Apr 17, 2023 · 1 comment
Closed

Pattern matching on quoted.Type crashes #284

matil019 opened this issue Apr 17, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@matil019
Copy link

If a source file contains a pattern matching on scala.quoted.Type, an exception tastyquery.Exceptions$TastyFormatException: Unexpected type tag BLOCK is thrown. This affects Tasty-MiMa.

Minimal example:

// the-lib/src/main/scala/foo/package.scala
package foo

import scala.quoted.*

def fooMacro(using Quotes): Expr[Unit] =
  Type.of[Any] match {
    case '[r] => '{()}
  }
// run.scala
import java.nio.file.FileSystems
import java.nio.file.Path

import tastyquery.Contexts
import tastyquery.Contexts.Context
import tastyquery.jdk.ClasspathLoaders

@main def run(): Unit = println{
  val cp = ClasspathLoaders.read(List(
    FileSystems.getFileSystem(java.net.URI.create("jrt:/")).getPath("modules", "java.base"),
    Path.of("the-lib/target/scala-3.2.2/classes"),
  ))
  given ctx: Context = Contexts.init(cp)
  ctx.findPackage("foo").declarations
}
//  build.sbt
ThisBuild / scalaVersion := "3.2.2"

lazy val `the-lib` = project

libraryDependencies += "ch.epfl.scala" %% "tasty-query" % "0.7.3"
# project/build.properties
sbt.version=1.8.2

Running tasty-query in run.scala:

$ sbt clean compile run
[info] welcome to sbt 1.8.2 (Oracle Corporation Java 11.0.18)
...
[info] running run
[error] tastyquery.Exceptions$TastyFormatException: Unexpected type tag BLOCK at address Addr(233) in file the-lib/target/scala-3.2.2/classes/foo/package$package.tasty
[error]         at tastyquery.reader.tasties.TreeUnpickler.readType(TreeUnpickler.scala:1171)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTypeTree(TreeUnpickler.scala:1376)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTerm$$anonfun$1(TreeUnpickler.scala:807)
[error]         at dotty.tools.tasty.TastyReader.until(TastyReader.scala:125)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTerm(TreeUnpickler.scala:807)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTerm(TreeUnpickler.scala:795)
[error]         at tastyquery.reader.tasties.TreeUnpickler.$anonfun$15(TreeUnpickler.scala:753)
[error]         at dotty.tools.tasty.TastyReader.collectWhile(TastyReader.scala:137)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readPattern(TreeUnpickler.scala:754)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readCaseDef(TreeUnpickler.scala:1012)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readCases$$anonfun$2(TreeUnpickler.scala:1003)
[error]         at dotty.tools.tasty.TastyReader.collectWhile(TastyReader.scala:137)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readCases(TreeUnpickler.scala:1004)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTerm(TreeUnpickler.scala:899)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readValOrDefDef(TreeUnpickler.scala:660)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readStat(TreeUnpickler.scala:423)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readStats$$anonfun$1(TreeUnpickler.scala:367)
[error]         at dotty.tools.tasty.TastyReader.until(TastyReader.scala:125)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readStats(TreeUnpickler.scala:367)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTemplate(TreeUnpickler.scala:597)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readStat(TreeUnpickler.scala:406)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTopLevelStat(TreeUnpickler.scala:363)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTopLevelStat$$anonfun$1(TreeUnpickler.scala:362)
[error]         at dotty.tools.tasty.TastyReader.until(TastyReader.scala:125)
[error]         at tastyquery.reader.tasties.TreeUnpickler.readTopLevelStat(TreeUnpickler.scala:362)
[error]         at tastyquery.reader.tasties.TreeUnpickler.read$1(TreeUnpickler.scala:46)
[error]         at tastyquery.reader.tasties.TreeUnpickler.unpickle(TreeUnpickler.scala:50)
[error]         at tastyquery.reader.Loaders$Loader.enterTasty$1(Loaders.scala:109)
[error]         at tastyquery.reader.Loaders$Loader.inspectClass$1(Loaders.scala:95)
[error]         at tastyquery.reader.Loaders$Loader.completeRoot(Loaders.scala:136)
[error]         at tastyquery.reader.Loaders$Loader.loadAllRoots$$anonfun$1$$anonfun$2(Loaders.scala:147)
[error]         at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error]         at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error]         at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
[error]         at scala.IArray$package$IArray$.foreach(IArray.scala:123)
[error]         at tastyquery.reader.Loaders$Loader.loadAllRoots$$anonfun$1(Loaders.scala:147)
[error]         at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error]         at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error]         at scala.Option.foreach(Option.scala:437)
[error]         at tastyquery.reader.Loaders$Loader.loadAllRoots(Loaders.scala:147)
[error]         at tastyquery.Symbols$PackageSymbol.declarations(Symbols.scala:1347)
[error]         at run$package$.run(run.scala:14)
[error]         at run.main(run.scala:8)
[error]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) tastyquery.Exceptions$TastyFormatException: Unexpected type tag BLOCK at address Addr(233) in file the-lib/target/scala-3.2.2/classes/foo/package$package.tasty
[error] Total time: 0 s, completed Apr 17, 2023, 5:29:42 PM

Expected result

The call to ctx.findPackage("foo").declarations succeeds, its result value (List) is printed.

@bishabosha
Copy link
Member

Thanks for finding this!

@sjrd sjrd self-assigned this Apr 17, 2023
@sjrd sjrd added the bug Something isn't working label Apr 17, 2023
bishabosha added a commit that referenced this issue Apr 17, 2023
Fix #284: Read BLOCK's in TypeTree position as TypeBindingsTree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants