Repository: scalacenter/tasty-query
Pull request #449 (2025-01-14 13:50:54)

Upgrade to Scala 3.6.3.
With changes to the inferred bound of match types.


Patch:
diff --git a/build.sbt b/build.sbt
index e96269d..b8211c8 100644
--- a/build.sbt
+++ b/build.sbt
@@ -3,7 +3,7 @@ import sbt.internal.util.ManagedLogger
 
 import org.scalajs.jsenv.nodejs.NodeJSEnv
 
-val usedScalaCompiler = "3.5.0"
+val usedScalaCompiler = "3.6.2"
 val usedTastyRelease = usedScalaCompiler
 val scala2Version = "2.13.14"
 
@@ -37,7 +37,7 @@ inThisBuild(Def.settings(
     Developer("sjrd", "Sébastien Doeraene", "sjrdoeraene@gmail.com", url("https://github.com/sjrd/")),
     Developer("bishabosha", "Jamie Thompson", "bishbashboshjt@gmail.com", url("https://github.com/bishabosha")),
   ),
-  versionPolicyIntention := Compatibility.BinaryAndSourceCompatible,
+  versionPolicyIntention := Compatibility.BinaryCompatible,
   // Ignore dependencies to internal modules whose version is like `1.2.3+4...` (see https://github.com/scalacenter/sbt-version-policy#how-to-integrate-with-sbt-dynver)
   versionPolicyIgnoredInternalDependencyVersions := Some("^\\d+\\.\\d+\\.\\d+\\+\\d+".r)
 ))
@@ -129,7 +129,8 @@ lazy val tastyQuery =
         )
       },
 
-      tastyMiMaPreviousArtifacts := mimaPreviousArtifacts.value,
+      // Temporarily disabled until we have a published version of tasty-query that can handle 3.4.x.
+      //tastyMiMaPreviousArtifacts := mimaPreviousArtifacts.value,
       tastyMiMaConfig ~= { prev =>
         import tastymima.intf._
         prev
diff --git a/tasty-query/shared/src/main/scala/tastyquery/reader/tasties/TastyFormat.scala b/tasty-query/shared/src/main/scala/tastyquery/reader/tasties/TastyFormat.scala
index 185bc48..2045f34 100644
--- a/tasty-query/shared/src/main/scala/tastyquery/reader/tasties/TastyFormat.scala
+++ b/tasty-query/shared/src/main/scala/tastyquery/reader/tasties/TastyFormat.scala
@@ -296,7 +296,7 @@ private[tasties] object TastyFormat:
     * compatibility, but remains backwards compatible, with all
     * preceeding `MinorVersion`.
     */
-  final val MinorVersion: Int = 5
+  final val MinorVersion: Int = 6
 
   /** Natural Number. The `ExperimentalVersion` allows for
     * experimentation with changes to TASTy without committing


Test patch:
diff --git a/tasty-query/shared/src/test/scala/tastyquery/PrintersTest.scala b/tasty-query/shared/src/test/scala/tastyquery/PrintersTest.scala
index e7d6eb8..4e0fafa 100644
--- a/tasty-query/shared/src/test/scala/tastyquery/PrintersTest.scala
+++ b/tasty-query/shared/src/test/scala/tastyquery/PrintersTest.scala
@@ -211,7 +211,11 @@ class PrintersTest extends UnrestrictedUnpicklingSuite:
     )
 
     val MatchTypeClass = ctx.findTopLevelClass("simple_trees.MatchType")
-    testShowBasicMember(MatchTypeClass, typeName("MT"), "type MT[X] = X match { case Int => String }")
+    testShowBasicMember(
+      MatchTypeClass,
+      typeName("MT"),
+      "type MT[X] <: scala.Predef.String = X match { case Int => String }"
+    )
     testShowBasicMember(
       MatchTypeClass,
       typeName("MTWithBound"),
@@ -220,9 +224,13 @@ class PrintersTest extends UnrestrictedUnpicklingSuite:
     testShowBasicMember(
       MatchTypeClass,
       typeName("MTWithWildcard"),
-      "type MTWithWildcard[X] = X match { case _ => Int }"
+      "type MTWithWildcard[X] <: scala.Int = X match { case _ => Int }"
+    )
+    testShowBasicMember(
+      MatchTypeClass,
+      typeName("MTWithBind"),
+      "type MTWithBind[X] <: t = X match { case List[t] => t }"
     )
-    testShowBasicMember(MatchTypeClass, typeName("MTWithBind"), "type MTWithBind[X] = X match { case List[t] => t }")
   }
 
   testWithContext("multiline tree printers") {
@@ -286,7 +294,7 @@ class PrintersTest extends UnrestrictedUnpicklingSuite:
     testShowMultilineMember(
       MatchTypeClass,
       typeName("MT"),
-      """type MT[X] = X match {
+      """type MT[X] <: scala.Predef.String = X match {
         |  case Int => String
         |}""".stripMargin
     )
@@ -300,14 +308,14 @@ class PrintersTest extends UnrestrictedUnpicklingSuite:
     testShowMultilineMember(
       MatchTypeClass,
       typeName("MTWithWildcard"),
-      """type MTWithWildcard[X] = X match {
+      """type MTWithWildcard[X] <: scala.Int = X match {
         |  case _ => Int
         |}""".stripMargin
     )
     testShowMultilineMember(
       MatchTypeClass,
       typeName("MTWithBind"),
-      """type MTWithBind[X] = X match {
+      """type MTWithBind[X] <: t = X match {
         |  case List[t] => t
         |}""".stripMargin
     )
diff --git a/tasty-query/shared/src/test/scala/tastyquery/ReadTreeSuite.scala b/tasty-query/shared/src/test/scala/tastyquery/ReadTreeSuite.scala
index 7902736..fd5105c 100644
--- a/tasty-query/shared/src/test/scala/tastyquery/ReadTreeSuite.scala
+++ b/tasty-query/shared/src/test/scala/tastyquery/ReadTreeSuite.scala
@@ -56,6 +56,11 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
   private object ScalaPackageRef:
     def unapply(tree: PackageRef): Boolean = tree.fullyQualifiedName.path == List(termName("scala"))
 
+  private object PredefRef:
+    def unapply(tree: TermRef): Boolean = tree match
+      case TermRefInternal(ScalaPackageRef(), SimpleName("Predef")) => true
+      case _                                                        => false
+
   private object ScalaCollImmutablePackageRef:
     def unapply(tree: PackageRef): Boolean =
       tree.fullyQualifiedName.path == List(termName("scala"), termName("collection"), termName("immutable"))
@@ -1529,7 +1534,7 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
             TypeWrapper(
               ty.OrType(
                 TypeRefInternal(ScalaPackageRef(), SimpleTypeName("Int")),
-                TypeRefInternal(TermRefInternal(ScalaPackageRef(), SimpleName("Predef")), SimpleTypeName("String"))
+                TypeRefInternal(PredefRef(), SimpleTypeName("String"))
               )
             ),
             _,
@@ -1904,8 +1909,8 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
               List(TypeParam(SimpleTypeName("X"), NothingAnyTypeBoundsTree(), _)),
               TypeAliasDefinitionTree(
                 MatchTypeTree(
-                  // No bound on the match result
-                  TypeWrapper(TypeRefInternal(ScalaPackageRef(), tpnme.Any)),
+                  // No bound on the match result -- inferred to be String
+                  TypeWrapper(TypeRefInternal(PredefRef(), tpnme.String)),
                   TypeIdent(SimpleTypeName("X")),
                   List(TypeCaseDef(TypeIdent(SimpleTypeName("Int")), TypeIdent(SimpleTypeName("String"))))
                 )
@@ -1946,8 +1951,8 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
               List(TypeParam(SimpleTypeName("X"), NothingAnyTypeBoundsTree(), _)),
               TypeAliasDefinitionTree(
                 MatchTypeTree(
-                  // No bound on the match result
-                  TypeWrapper(TypeRefInternal(ScalaPackageRef(), tpnme.Any)),
+                  // No bound on the match result -- inferred to be Int
+                  TypeWrapper(TypeRefInternal(ScalaPackageRef(), tpnme.Int)),
                   TypeIdent(SimpleTypeName("X")),
                   List(TypeCaseDef(TypeIdent(tpnme.Wildcard), TypeIdent(SimpleTypeName("Int"))))
                 )
@@ -1965,8 +1970,8 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
               List(TypeParam(SimpleTypeName("X"), NothingAnyTypeBoundsTree(), _)),
               TypeAliasDefinitionTree(
                 MatchTypeTree(
-                  // No bound on the match result
-                  TypeWrapper(TypeRefInternal(ScalaPackageRef(), tpnme.Any)),
+                  // No bound on the match result -> (erroneously) inferred to `t`
+                  TypeWrapper(_),
                   TypeIdent(SimpleTypeName("X")),
                   List(
                     TypeCaseDef(
@@ -1995,16 +2000,13 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
                 Select(rhs, SignedName(SimpleName("$asInstanceOf$"), _, _)),
                 TypeWrapper(
                   ty.MatchType(
-                    TypeRefInternal(ScalaPackageRef(), SimpleTypeName("Any")),
+                    TypeRefInternal(PredefRef(), SimpleTypeName("String")),
                     TypeRefInternal(_, xRef),
                     List(
                       ty.MatchTypeCase(
                         Nil,
                         TypeRefInternal(ScalaPackageRef(), SimpleTypeName("Int")),
-                        TypeRefInternal(
-                          TermRefInternal(ScalaPackageRef(), SimpleName("Predef")),
-                          SimpleTypeName("String")
-                        )
+                        TypeRefInternal(PredefRef(), SimpleTypeName("String"))
                       )
                     )
                   )
@@ -2026,7 +2028,7 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
                 Select(rhs, SignedName(SimpleName("$asInstanceOf$"), _, _)),
                 TypeWrapper(
                   ty.MatchType(
-                    TypeRefInternal(ScalaPackageRef(), SimpleTypeName("Any")),
+                    _, // erroneously inferred to `t`
                     TypeRefInternal(_, xRef),
                     List(
                       ty.MatchTypeCase(
@@ -2252,9 +2254,7 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
         sym
     }
     assert(clue(javaAnnotWithDefaultImplicitSym.annotations).sizeIs == 1)
-    val javaAnnotWithDefaultImplicitAnnotCheck: StructureCheck = {
-      case Apply(Select(New(_), _), List(ident @ Ident(nme.Wildcard)))
-          if ident.tpe eq defn.uninitializedMethodTermRef =>
+    val javaAnnotWithDefaultImplicitAnnotCheck: StructureCheck = { case Apply(Select(New(_), _), Nil) =>
     }
     assert(
       containsSubtree(javaAnnotWithDefaultImplicitAnnotCheck)(clue(javaAnnotWithDefaultImplicitSym.annotations(0).tree))
@@ -2266,7 +2266,7 @@ class ReadTreeSuite extends RestrictedUnpicklingSuite {
     }
     assert(clue(javaAnnotWithDefaultExplicitSym.annotations).sizeIs == 1)
     val javaAnnotWithDefaultExplicitAnnotCheck: StructureCheck = {
-      case Apply(Select(New(_), _), List(Literal(Constant(false)))) =>
+      case Apply(Select(New(_), _), List(NamedArg(SimpleName("value"), Literal(Constant(false))))) =>
     }
     assert(
       containsSubtree(javaAnnotWithDefaultExplicitAnnotCheck)(clue(javaAnnotWithDefaultExplicitSym.annotations(0).tree))
diff --git a/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala b/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
index 261e9a4..da8992c 100644
--- a/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
+++ b/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
@@ -408,7 +408,7 @@ class SignatureSuite extends UnrestrictedUnpicklingSuite:
     val MatchType = ctx.findTopLevelClass("simple_trees.MatchType")
 
     val unboundUnreducibleSig = MatchType.findNonOverloadedDecl(termName("unboundUnreducibleSig"))
-    assertSigned(unboundUnreducibleSig, "(1,java.lang.Object):java.lang.Object")
+    assertSigned(unboundUnreducibleSig, "(1,java.lang.Object):java.lang.String")
 
     val unboundReducibleSig = MatchType.findNonOverloadedDecl(termName("unboundReducibleSig"))
     assertSigned(unboundReducibleSig, "(1,scala.Int):java.lang.String")
@@ -419,9 +419,9 @@ class SignatureSuite extends UnrestrictedUnpicklingSuite:
     val boundReducibleSig = MatchType.findNonOverloadedDecl(termName("boundReducibleSig"))
     assertSigned(boundReducibleSig, "(1,scala.Int):scala.Some")
 
-    // this one is suspicious, but it is what dotc does (I expected `Object` instead of `Object[]`)
+    // this one is suspicious, but it is what dotc does (I expected `Object` instead of `String[]`)
     val arrayOfUnboundUnreducibleSig = MatchType.findNonOverloadedDecl(termName("arrayOfUnboundUnreducibleSig"))
-    assertSigned(arrayOfUnboundUnreducibleSig, "(1,java.lang.Object):java.lang.Object[]")
+    assertSigned(arrayOfUnboundUnreducibleSig, "(1,java.lang.Object):java.lang.String[]")
 
     val arrayOfUnboundReducibleSig = MatchType.findNonOverloadedDecl(termName("arrayOfUnboundReducibleSig"))
     assertSigned(arrayOfUnboundReducibleSig, "(1,scala.Int):java.lang.String[]")