Skip to content

chore: fix parameterless calls to functions #23204

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

Merged
merged 2 commits into from
May 20, 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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/MainGenericRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ object MainGenericRunner {
.withScriptArgs(tail*)
.noSave // -save not useful here
case arg :: tail =>
val line = Try(Source.fromFile(arg).getLines.toList).toOption.flatMap(_.headOption)
val line = Try(Source.fromFile(arg).getLines().toList).toOption.flatMap(_.headOption)
lazy val hasScalaHashbang = { val s = line.getOrElse("") ; s.startsWith("#!") && s.contains("scala") }
if arg.endsWith(".scala") || arg.endsWith(".sc") || hasScalaHashbang then
settings
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/root.scala
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ object root:
val it = seen.iterator
var ref: CaptureRef | Null = null
while it.hasNext && ref == null do
val (k, v) = it.next
val (k, v) = it.next()
if v.annot eq t.annot then ref = k
if ref == null then
ref = Fresh(Origin.Unknown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
var file: AbstractFile | Null = base
val dirParts = pathParts.init.iterator
while (dirParts.hasNext) {
val dirPart = dirParts.next
val dirPart = dirParts.next()
file = file.lookupName(dirPart, directory = true)
if (file == null)
return null
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ object Contexts {
def outersIterator: Iterator[Context] = new Iterator[Context] {
var current = thiscontext
def hasNext = current != NoContext
def next = { val c = current; current = current.outer; c }
def next() = { val c = current; current = current.outer; c }
}

def period: Period
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ object SymDenotations {
final def ownersIterator(using Context): Iterator[Symbol] = new Iterator[Symbol] {
private var current = symbol
def hasNext = current.exists
def next: Symbol = {
def next(): Symbol = {
val result = current
current = current.owner
result
Expand Down Expand Up @@ -1418,7 +1418,7 @@ object SymDenotations {
final def nextOverriddenSymbol(using Context): Symbol = {
val overridden = allOverriddenSymbols
if (overridden.hasNext)
overridden.next
overridden.next()
else
NoSymbol
}
Expand Down Expand Up @@ -1496,10 +1496,10 @@ object SymDenotations {
val candidates = owner.info.decls.lookupAll(name)
def test(sym: Symbol): Symbol =
if (sym == symbol || sym.signature == signature) sym
else if (candidates.hasNext) test(candidates.next)
else if (candidates.hasNext) test(candidates.next())
else NoSymbol
if (candidates.hasNext) {
val sym = candidates.next
val sym = candidates.next()
if (candidates.hasNext) test(sym) else sym
}
else NoSymbol
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ object Types extends TypeUtils {
def underlyingIterator(using Context): Iterator[Type] = new Iterator[Type] {
var current = Type.this
var hasNext = true
def next = {
def next() = {
val res = current
hasNext = current.isInstanceOf[TypeProxy]
if (hasNext) current = current.asInstanceOf[TypeProxy].underlying
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object TastyPrinter:
else if arg.endsWith(".jar") then
val jar = JarArchive.open(Path(arg), create = false)
try
for file <- jar.iterator() if file.hasTastyExtension do
for file <- jar.iterator if file.hasTastyExtension do
printTasty(s"$arg ${file.path}", file.toByteArray, isBestEffortTasty = false)
finally jar.close()
else
Expand Down Expand Up @@ -123,7 +123,7 @@ class TastyPrinter(bytes: Array[Byte], isBestEffortTasty: Boolean, val testPickl
unpickle0(new PositionSectionUnpickler(sb))
unpickle0(new CommentSectionUnpickler(sb))
unpickle0(new AttributesSectionUnpickler(sb))
sb.result
sb.result()
}

def unpickle0[R](sec: PrinterSectionUnpickler[R])(using NameRefs): Option[R] =
Expand Down Expand Up @@ -266,7 +266,7 @@ class TastyPrinter(bytes: Array[Byte], isBestEffortTasty: Boolean, val testPickl
val value = nameAtRef(utf8Ref).toString
sb.append(nameStr(s" ${utf8Ref.index} [$value]"))
sb.append("\n")
sb.result
sb.result()
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ class TastyPrinter(bytes: Array[Byte], isBestEffortTasty: Boolean, val testPickl
for ((_, nameRef) <- sources.iterator) {
buf += nameRef
}
NameRefs(buf.result)
NameRefs(buf.result())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
val it = mp.keysIterator
var i = 0
while i < keys.length do
keys(i) = it.next
keys(i) = it.next()
i += 1
assert(!it.hasNext)
i = 0
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ class Inliner(val call: tpd.Tree)(using Context):
// call. This way, a defensively written rewrite method can always
// report bad inputs at the point of call instead of revealing its internals.
val callToReport = if (enclosingInlineds.nonEmpty) enclosingInlineds.last else call
val ctxToReport = ctx.outersIterator.dropWhile(enclosingInlineds(using _).nonEmpty).next
val ctxToReport = ctx.outersIterator.dropWhile(enclosingInlineds(using _).nonEmpty).next()
// The context in which we report should still use the existing context reporter
val ctxOrigReporter = ctxToReport.fresh.setReporter(ctx.reporter)
inContext(ctxOrigReporter) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
case Some((_, _, args)) => args.iterator
case _ => Iterator.empty
def nextArgument() =
if argsIt.hasNext then argsIt.next
if argsIt.hasNext then argsIt.next()
else
assert(
impl.parents.forall(_.tpe.typeSymbol != mixin),
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class PickleQuotes extends MacroTransform {

/** Get the holeContents of the transformed tree */
def getContents() =
val res = holeContents.result
val res = holeContents.result()
holeContents.clear()
res
end HoleContentExtractor
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/io/AbstractFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
}

/** Returns all abstract subfiles of this abstract directory. */
def iterator(): Iterator[AbstractFile]
def iterator: Iterator[AbstractFile]

/** Drill down through subdirs looking for the target, as in lookupName.
* Ths target name is the last of parts.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/io/PlainFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.nio.file.{InvalidPathException, Paths}
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
override val isDirectory: Boolean = true
override def iterator(): Iterator[PlainFile] = givenPath.list.filter(_.exists).map(new PlainFile(_))
override def iterator: Iterator[PlainFile] = givenPath.list.filter(_.exists).map(new PlainFile(_))
}

/** This class implements an abstract file backed by a File.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/io/VirtualDirectory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extends AbstractFile {

// the toList is so that the directory may continue to be
// modified while its elements are iterated
def iterator(): Iterator[AbstractFile] = files.values.toList.iterator
def iterator: Iterator[AbstractFile] = files.values.toList.iterator

override def lookupName(name: String, directory: Boolean): AbstractFile =
(files get name filter (_.isDirectory == directory)).orNull
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/io/ZipArchive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ final class FileZipArchive(jpath: JPath, release: Option[String]) extends ZipArc
}

final class ManifestResources(val url: URL) extends ZipArchive(null, None) {
def iterator(): Iterator[AbstractFile] = {
def iterator: Iterator[AbstractFile] = {
val root = new DirEntry("/", null)
val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
val stream = input
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/SettingsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class SettingsTests {
assertNotEquals(file1StateBefore, String(Files.readAllBytes(file1)))
assertEquals(file2StateBefore, String(Files.readAllBytes(file2)))

}(Files.deleteIfExists(_), Files.deleteIfExists(_))
}(using Files.deleteIfExists(_), Files.deleteIfExists(_))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a warning, but we do not enable -Werror in the test. Unfortunately, this will change from implicit params to contextual params with the new library. Hence, I'm anticipating this error and I'm fixing it here.


@Test def `Output side effect is not present when setting is deprecated`: Unit =
val result = Using.resource(Files.createTempFile("myfile", ".jar")){ file =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PathPicklingTest {
val sb = new StringBuffer
val jar = JarArchive.open(Path(s"$out/out.jar"), create = false)
try
for file <- jar.iterator() if file.name.endsWith(".tasty") do
for file <- jar.iterator if file.name.endsWith(".tasty") do
sb.append(TastyPrinter.showContents(file.toByteArray, noColor = true, isBestEffortTasty = false))
finally jar.close()
sb.toString()
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension (str: String) def dropExtension =

private
def withFile[T](file: File)(action: Source => T): T = resource(Source.fromFile(file, UTF_8.name))(action)
def readLines(f: File): List[String] = withFile(f)(_.getLines.toList)
def readLines(f: File): List[String] = withFile(f)(_.getLines().toList)
def readFile(f: File): String = withFile(f)(_.mkString)

private object Unthrown extends ControlThrowable
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
count += 1
for file <- files if isSourceFile(file) do
Using.resource(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
source.getLines.zipWithIndex.foreach: (line, lineNbr) =>
source.getLines().zipWithIndex.foreach: (line, lineNbr) =>
comment.findAllMatchIn(line).foreach:
case comment("nopos-") => bump("nopos")
case _ => bump(s"${file.getPath}:${lineNbr+1}")
Expand Down Expand Up @@ -980,7 +980,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
expectedErrors += 1
files.filter(isSourceFile).foreach { file =>
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
source.getLines().zipWithIndex.foreach { case (line, lineNbr) =>
comment.findAllMatchIn(line).foreach { m =>
m.group(2) match
case prefix if m.group(1).isEmpty =>
Expand Down
Loading