Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix deprecated auto application of () to method invocations #1422

Merged
merged 1 commit into from
Feb 6, 2025
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
19 changes: 12 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,23 @@ def buildScalacOptions(scalaVersion: String) = {
"-unchecked",
"-Xfatal-warnings",
"-Xxml:-coalescing",
"-Xfuture",
"-Ywarn-infer-any",
"-Ywarn-inaccessible",
// "-Ywarn-nullary-unit", // we cannot use this. It interferes with the Uniform Access Principle.
// See https://stackoverflow.com/questions/7600910/difference-between-function-with-parentheses-and-without.
"-Ywarn-unused-import"
"-Ywarn-unused:imports"
)

val scalaVersionSpecificOptions = CrossVersion.partialVersion(scalaVersion) match {
case Some((2, 12)) =>
Seq(
"-Ywarn-unused:imports"
"-Xfuture",
"-Ywarn-infer-any",
"-Ywarn-inaccessible"
// "-Ywarn-nullary-unit", // we cannot use this. It interferes with the Uniform Access Principle.
// See https://stackoverflow.com/questions/7600910/difference-between-function-with-parentheses-and-without.
)
case Some((2, 13)) =>
Seq(
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:nullary-unit"
)
case _ => Seq.empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ trait TheExamplePropMixin extends PropertyMixin { self: HasMixin =>
var initWasCalled: Boolean = false
def init() = {
initWasCalled = true
registerToStringFunction(() => theExamplePropToString)
registerToStringFunction(() => theExamplePropToString())
}

init() // call at object creation to initialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import org.apache.daffodil.lib.xml.NS
object Implicits {

object ImplicitsSuppressUnusedImportWarning {
def apply() = if (scala.math.random.isNaN()) Assert.impossible()
// $COVERAGE-OFF$
def apply() = if (scala.math.random().isNaN) Assert.impossible()
Copy link
Contributor

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.

// $COVERAGE-ON$
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import org.apache.daffodil.lib.exceptions.Assert
package object equality {

def EqualitySuppressUnusedImportWarning() = {
if (scala.math.random.isNaN) Assert.impossible()
// $COVERAGE-OFF$
if (scala.math.random().isNaN) Assert.impossible()
// $COVERAGE-ON$
}

// Convertible types - strongly typed equality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ trait OrderedCalendar { self: DFDLCalendar =>

// Step 1 of the algorithm is to normalize the dates to Z time zone.
//
val pPrime = p.getNormalizedCalendar
val qPrime = q.getNormalizedCalendar
val pPrime = p.getNormalizedCalendar()
val qPrime = q.getNormalizedCalendar()

val res: DFDLCalendarOrder = {
if ((pHasTZ && qHasTZ) || (!pHasTZ && !qHasTZ)) { orderCompareFields(pPrime, qPrime) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ object OOLAG {
*/
def isError: Boolean = isErrorOnce
private lazy val isErrorOnce: Boolean = {
oolagRoot.checkErrors
oolagRoot.checkErrors()
val errorCount = oolagRoot.errors.size
errorCount > 0
}
Expand Down Expand Up @@ -703,7 +703,7 @@ object OOLAG {
// this should make a substantial difference in schema compilation time.
val res =
try {
oolagBefore
oolagBefore()
val v = body // good place for a breakpoint
oolagAfterValue(v.asInstanceOf[AnyRef])
v
Expand All @@ -714,7 +714,7 @@ object OOLAG {
case e: Error => throw e
case th: Throwable => oolagCatch(th)
} finally {
oolagFinalize
oolagFinalize()
}
res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class MStackOfBoolean private ()
object MStackOfBoolean {
def apply() = {
val stk = new MStackOfBoolean()
stk.init
stk.init()
stk
}
}
Expand All @@ -49,7 +49,7 @@ final class MStackOfInt extends MStack[Int]((n: Int) => new Array[Int](n), 0)
object MStackOfInt {
def apply() = {
val stk = new MStackOfInt()
stk.init
stk.init()
stk
}
}
Expand All @@ -59,7 +59,7 @@ final class MStackOfLong extends MStack[Long]((n: Int) => new Array[Long](n), 0L
object MStackOfLong {
def apply() = {
val stk = new MStackOfLong()
stk.init
stk.init()
stk
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ final class MStackOf[T <: AnyRef] extends Serializable {
@inline final def reset(m: MStack.Mark) = delegate.reset(m)

@inline final def push(t: T) = delegate.push(t)
@inline final def pop: T = delegate.pop.asInstanceOf[T]
@inline final def pop: T = delegate.pop().asInstanceOf[T]
@inline final def setTop(t: T) = delegate.setTop(t)
@inline final def top: T = delegate.top.asInstanceOf[T]
@inline final def bottom: T = delegate.bottom.asInstanceOf[T]
Expand All @@ -169,7 +169,7 @@ private[util] final class MStackOfAnyRef private ()
object MStackOfAnyRef {
def apply() = {
val stk = new MStackOfAnyRef()
stk.init
stk.init()
stk
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class TransitiveClosure[T] {
*/
private def tclose() = {
while (!items.isEmpty) {
val hd = items.dequeue
val hd = items.dequeue()
if (!processed.contains(hd)) {
processed += hd
val newOnes = func(hd).filterNot(processed.contains(_)).distinct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

}

def makeConfig(uris: Seq[String]): Config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ object XMLUtils {

pos += 1
}
list
list.toSeq
}

private val remapXMLToPUA =
Expand Down Expand Up @@ -276,13 +276,13 @@ object XMLUtils {
}
} else {
// not an atom
processText // if there is pending text output that first
processText() // if there is pending text output that first
ab += current // then the current non-atom node.
}
}
// we fell out of the loop. So
processText // in case there is text left pending when we hit the end
ab.result
processText() // in case there is text left pending when we hit the end
ab.result()
}

val XSD_NAMESPACE = NS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestEqualityOperators {
fail("equal")
}

private val ylong = scala.math.random.toLong
private val ylong = scala.math.random().toLong

@Test
def testStronglyTypedEqualityInline(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ object IOMacros {

import c.universe._

val dStream = TermName(c.freshName)
val newLengthLimit = TermName(c.freshName)
val savedLengthLimit = TermName(c.freshName)
val dStream = TermName(c.freshName())
val newLengthLimit = TermName(c.freshName())
val savedLengthLimit = TermName(c.freshName())
// c.prefix is the expression this macro was expanded on. Not quite same thing as 'this' because we have to be
// careful not to use it more than once or it will evaluate more than once.
val selfExp = c.prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ object TimeTrackerMacros {
def trackMacro(c: Context)(name: c.Tree)(body: c.Tree) = {
import c.universe._

val startTime = TermName(c.freshName)
val endTime = TermName(c.freshName)
val childrenTime = TermName(c.freshName)
val timeTaken = TermName(c.freshName)
val selfTime = TermName(c.freshName)
val sectionTime = TermName(c.freshName)
val result = TermName(c.freshName)
val key = TermName(c.freshName)
val startTime = TermName(c.freshName())
val endTime = TermName(c.freshName())
val childrenTime = TermName(c.freshName())
val timeTaken = TermName(c.freshName())
val selfTime = TermName(c.freshName())
val sectionTime = TermName(c.freshName())
val result = TermName(c.freshName())
val key = TermName(c.freshName())

q"""
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PropertyGenerator(arg: Node) {
}
}
})
thunks
thunks.toSeq
}

/**
Expand Down Expand Up @@ -430,7 +430,7 @@ trait CurrencyMixin extends PropertyMixin {
}

final def currencyInit() = {
registerToStringFunction(() => currencyToString)
registerToStringFunction(() => currencyToString())
}

currencyInit() // call at object creation to initialize
Expand Down Expand Up @@ -687,12 +687,12 @@ object Currency {
stripLast
}

def initialUpperCase(s: String): String = s.head.toUpper + s.substring(1)
def initialUpperCase(s: String): String = s.head.toUpper +: s.substring(1)
def initialLowerCase(s: String): String = {
// special case for the way we lowercase the utf16Width property.
if (s == "UTF16Width") "utf16Width"
else
s.head.toLower + s.substring(1)
s.head.toLower +: s.substring(1)
}

} // end trait
Expand Down Expand Up @@ -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 = outDir + "/" + filename
val outPath = s"$outDir/$filename"
outPath
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class EnumListTunable(
"Nil"
} else {
val defaultSeq =
trimmedDefault.split("\\s+").map(d => s"${listType}.${d.head.toUpper + d.tail}")
trimmedDefault.split("\\s+").map(d => s"${listType}.${d.head.toUpper}${d.tail}")
s"""Seq(${defaultSeq.mkString(", ")})"""
}

Expand All @@ -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 = nodeName.head.toUpper +: nodeName.tail

/**
* Returns a list of all string values of enumerations. If a simpletype is a
Expand Down Expand Up @@ -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 => e.head.toUpper +: e.tail }
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 => e.head.toUpper +: e.tail }
scalaEnumValues.mkString(" override lazy val values = Array(", ", ", ")")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class WarnIDGenerator(schema: scala.xml.Node) {

val scalaNames = enumerationNodes.map { node =>
val enumName = node \@ "value"
val scalaName = enumName.head.toUpper + enumName.tail
val scalaName = enumName.head.toUpper +: enumName.tail
scalaName
}

Expand Down