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

skip scalameta bug 2921 convert if new version #144

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scalameta_ast

import scala.meta.Tree

object ScalametaBug2921 {
def convert(t: Tree): String = t.structure
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scalameta_ast

import scala.meta.Tree

object ScalametaBug2921 {
// https://github.com/scalameta/scalameta/pull/2921
private[this] val scalametaBugWorkaround: Seq[(String, String)] = Seq(
"Lit.Unit(())" -> "Lit.Unit()",
"Lit.Null(null)" -> "Lit.Null()"
)

def convert(t: Tree): String = {
scalametaBugWorkaround.foldLeft(t.structure) { case (s, (x1, x2)) =>
s.replace(x1, x2)
}
}
}
11 changes: 1 addition & 10 deletions core/src/main/scala/scalameta_ast/ScalametaAST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ class ScalametaAST {

private val convert = implicitly[Convert[String, Input]]

// TODO remove when scalafix depends on new scalameta version
// https://github.com/scalameta/scalameta/pull/2921
private[this] val scalametaBugWorkaround: Seq[(String, String)] = Seq(
"Lit.Unit(())" -> "Lit.Unit()",
"Lit.Null(null)" -> "Lit.Null()"
)

private def isValidTermName(str: String): Boolean = {
implicitly[Parse[Term]].apply(Input.String(str), dialects.Scala3).toOption.exists(_.is[Term.Name])
}
Expand Down Expand Up @@ -310,9 +303,7 @@ class ScalametaAST {
x2 <- dialects
} yield (x1, x2)
)
val str = scalametaBugWorkaround.foldLeft(tree.structure) { case (s, (x1, x2)) =>
s.replace(x1, x2)
}
val str = ScalametaBug2921.convert(tree)
lazy val parsed = implicitly[Parse[Term]].apply(Input.String(str), scala.meta.dialects.Scala3).get
val parsedOpt = PartialFunction.condOpt(args) { case x: ScalafixRule =>
ParsedValue(() => parsed, x)
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/scalajvm/scalameta_ast/ScalametaBug2921.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package scalameta_ast

import scala.meta.Tree

object ScalametaBug2921 {
def convert(t: Tree): String = t.structure
}