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

ScalafmtReflectConfig: fix withoutRewriteRules #2923

Merged
merged 1 commit into from
Nov 26, 2021
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
Expand Up @@ -66,10 +66,12 @@ class ScalafmtReflectConfig private[dynamic] (val fmtReflect: ScalafmtReflect)(
val ctor: Constructor[_] = targetCls.getConstructors()(0)
val params = ctor.getParameters.map(_.getName)
val rewriteParamIdx = params.indexOf(rewriteFieldName).ensuring(_ >= 0)
val publicMethodNames = targetCls.getMethods.view.map(_.getName)
val publicParams = publicMethodNames.filter(params.contains).toSet
val fieldValues = params.zipWithIndex.map { case (p, i) =>
target.invoke(
if (i == rewriteParamIdx) "apply$default$" + (rewriteParamIdx + 1)
else p
else { if (publicParams.contains(p)) p else p + "$access$" + i }
)
}
new ScalafmtReflectConfig(fmtReflect)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class DynamicSuite extends FunSuite {
}

private val testedVersions = Seq(
"3.1.2",
"2.7.5",
"2.5.3",
"2.0.0-RC4",
"1.6.0-RC4",
Expand All @@ -190,8 +192,9 @@ class DynamicSuite extends FunSuite {
testedVersions.foreach { version =>
test(s"$name [v=$version]") {
val format = new Format(name, identity)
val dialect = if (version < "3.0.0") null else "scala213"
try {
format.setVersion(version, null, config(version))
format.setVersion(version, dialect, config(version))
fn(format, version)
} finally format.dynamic.clear()
}
Expand Down