-
Notifications
You must be signed in to change notification settings - Fork 73
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
Fix deprecated auto application of () to method invocations #1422
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
build.sbt
Outdated
Seq( | ||
"-Xlint:inaccessible", | ||
"-Xlint:infer-any", | ||
"-Xlint:nullary-unit", | ||
"-Ywarn-unused:imports" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Ywarn-unused:imports
is in both 2.12 and 2.13, should that be moved to the above commonOptions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like replacing simple string concatenation by string interpolations.
@@ -28,7 +28,7 @@ import org.apache.daffodil.lib.xml.NS | |||
object Implicits { | |||
|
|||
object ImplicitsSuppressUnusedImportWarning { | |||
def apply() = if (scala.math.random.isNaN()) Assert.impossible() | |||
def apply() = if (scala.math.random().isNaN) Assert.impossible() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the code coverage suppression comments around these.
@@ -57,7 +57,7 @@ object XercesValidatorFactory { | |||
if (config.hasPath(XercesValidator.name)) | |||
config.getStringList(XercesValidator.name).asScala | |||
else Seq.empty | |||
XercesValidator.fromFiles(schemaFiles) | |||
XercesValidator.fromFiles(schemaFiles.toSeq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so what exactly are the rules about when you must have the "()" and when not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out Scala 2.13 doesn't always complain about all nullary methods
"For reasons of backwards compatibility, Scala 3 for the moment also auto-inserts () for nullary methods that are defined in Scala 2, or that override a method defined in Scala 2."
Which toSeq seems to fall under, shall I add it to toSeq?
https://docs.scala-lang.org/scala3/reference/dropped-features/auto-apply.html
@@ -352,12 +352,12 @@ class TunableEnumDefinition( | |||
""".trim.stripMargin | |||
|
|||
private val scalaEnums = { | |||
val scalaEnumValues = allEnumerationValues.map { e => e.head.toUpper + e.tail } | |||
val scalaEnumValues = allEnumerationValues.map { e => s"${e.head.toUpper}${e.tail}" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are just concatenating strings then using "+" is clearer than the string interpolation which I must read very carefully to see if a whitespace is in there, or some other small characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Char + is conctatenation to a string is deprecated in 2.13, and string interpolation was the recommended fix from Intellij, we can either do that or convert the char to a string before using +. Though I prefer string interpolation personally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gaaak. A String is a Seq[Char]
. Appending T
to Seq[T]
at the front of the sequence is one of the most basic operations in functional programming. It is cons
from Lisp.
Perhaps +
is the wrong operator here? Maybe these should be the actual cons
operator i.e., is that char :: string
or char +: string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But to your point sticking with string concatenation will look something like
e/head.toUpper.toString + e.tail
Is that preferable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling toString is not, But e.head.toUpper +: e.tail
is preferable to the string interpolation.
@@ -316,7 +316,7 @@ class TunableEnumDefinition( | |||
simpleTypeNode: scala.xml.Node | |||
) { | |||
private val nodeName = (simpleTypeNode \@ "name").stripPrefix("Tunable") | |||
private val scalaType = nodeName.head.toUpper + nodeName.tail | |||
private val scalaType = s"${nodeName.head.toUpper}${nodeName.tail}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string concat with + was clearer.
scalaEnumValues.map { e => s""" case object ${e} extends ${scalaType}""" } | ||
} | ||
|
||
private val values = { | ||
val scalaEnumValues = allEnumerationValues.map { e => e.head.toUpper + e.tail } | ||
val scalaEnumValues = allEnumerationValues.map { e => s"${e.head.toUpper}${e.tail}" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer string concat not be done by string interpolations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 suggestions.
Plus, you also should suppress those codeCov things with their "COVERAGE-OFF" comment stuff.
@@ -292,7 +292,7 @@ class EnumListTunable( | |||
"Nil" | |||
} else { | |||
val defaultSeq = | |||
trimmedDefault.split("\\s+").map(d => s"${listType}.${s"${d.head.toUpper}${d.tail}"}") | |||
trimmedDefault.split("\\s+").map(d => s"${listType}.${d.head.toUpper +: d.tail}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, this one is not just concatenating two strings.
So in this case a single string interpolation is the right thing.
s"${listType}.${d.head.toUpper}${d.tail}"
@@ -762,7 +762,7 @@ import org.apache.daffodil.lib.exceptions.ThrowsSDE | |||
def getGeneratedFilePath(rootDir: String, pkg: String, filename: String): String = { | |||
val outDir = new java.io.File(rootDir + "/" + pkg.split('.').reduceLeft(_ + "/" + _)) | |||
outDir.mkdirs() | |||
val outPath = s"$outDir/$filename" | |||
val outPath = String.valueOf(outDir) + "/" + filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not just concatenating two strings, so I think this is better as a string interpolation, particularly as it avoids the String.valueOf call.
- add support for 2.13 scala options - add explicit () to some method invocations - fix some collections to explicitly used toSeq to return an immutable Seq - replace string concat with + with interpolated strings or char prepend where appropriate - add coverage comments DAFFODIL-2152
e5c12e0
to
4b7e02b
Compare
DAFFODIL-2152