From 73343e344e07bf05ab27651cd254f7ff16a47163 Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Mon, 19 May 2025 23:52:08 +0200 Subject: [PATCH 1/2] chore: fix type of some methods of Iterator --- compiler/src/dotty/tools/MainGenericRunner.scala | 2 +- compiler/src/dotty/tools/dotc/cc/root.scala | 2 +- .../tools/dotc/classpath/VirtualDirectoryClassPath.scala | 2 +- compiler/src/dotty/tools/dotc/core/Contexts.scala | 2 +- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 8 ++++---- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- .../src/dotty/tools/dotc/core/tasty/TastyPrinter.scala | 8 ++++---- .../src/dotty/tools/dotc/core/tasty/TreePickler.scala | 2 +- compiler/src/dotty/tools/dotc/inlines/Inliner.scala | 2 +- compiler/src/dotty/tools/dotc/transform/Mixin.scala | 2 +- .../src/dotty/tools/dotc/transform/PickleQuotes.scala | 2 +- compiler/src/dotty/tools/io/AbstractFile.scala | 2 +- compiler/src/dotty/tools/io/PlainFile.scala | 2 +- compiler/src/dotty/tools/io/VirtualDirectory.scala | 2 +- compiler/src/dotty/tools/io/ZipArchive.scala | 2 +- .../dotty/tools/dotc/core/tasty/PathPicklingTest.scala | 2 +- compiler/test/dotty/tools/utils.scala | 2 +- compiler/test/dotty/tools/vulpix/ParallelTesting.scala | 4 ++-- 18 files changed, 25 insertions(+), 25 deletions(-) diff --git a/compiler/src/dotty/tools/MainGenericRunner.scala b/compiler/src/dotty/tools/MainGenericRunner.scala index ef3893b8b846..b32630a5d63b 100644 --- a/compiler/src/dotty/tools/MainGenericRunner.scala +++ b/compiler/src/dotty/tools/MainGenericRunner.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/cc/root.scala b/compiler/src/dotty/tools/dotc/cc/root.scala index 3c6620678b09..36dd1c5661e3 100644 --- a/compiler/src/dotty/tools/dotc/cc/root.scala +++ b/compiler/src/dotty/tools/dotc/cc/root.scala @@ -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) diff --git a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala index bad52c0f4f58..9ed69942c596 100644 --- a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index e12ab1cc2da2..a867f90b237a 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 81a54cdc1f29..53f991806641 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -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 @@ -1418,7 +1418,7 @@ object SymDenotations { final def nextOverriddenSymbol(using Context): Symbol = { val overridden = allOverriddenSymbols if (overridden.hasNext) - overridden.next + overridden.next() else NoSymbol } @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index a1cfe7addf60..c2c508dc27ea 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala index ee798e29721e..df3ac411989b 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala @@ -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 @@ -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] = @@ -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() } } @@ -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()) } } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index cf9885d16d1f..f49e894df913 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 0268ae2b2f58..047ab80e6b0f 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -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) { diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 9a19c0dc414f..ce3f26071b77 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -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), diff --git a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala index 624ec9628d87..d9a1ea9ad9af 100644 --- a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala @@ -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 diff --git a/compiler/src/dotty/tools/io/AbstractFile.scala b/compiler/src/dotty/tools/io/AbstractFile.scala index c9d28f98f103..1bc9c051cdc6 100644 --- a/compiler/src/dotty/tools/io/AbstractFile.scala +++ b/compiler/src/dotty/tools/io/AbstractFile.scala @@ -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. diff --git a/compiler/src/dotty/tools/io/PlainFile.scala b/compiler/src/dotty/tools/io/PlainFile.scala index a6a39d9ff3eb..ff637c913cd8 100644 --- a/compiler/src/dotty/tools/io/PlainFile.scala +++ b/compiler/src/dotty/tools/io/PlainFile.scala @@ -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. diff --git a/compiler/src/dotty/tools/io/VirtualDirectory.scala b/compiler/src/dotty/tools/io/VirtualDirectory.scala index 949f2d0e61dd..28c4bc308cae 100644 --- a/compiler/src/dotty/tools/io/VirtualDirectory.scala +++ b/compiler/src/dotty/tools/io/VirtualDirectory.scala @@ -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 diff --git a/compiler/src/dotty/tools/io/ZipArchive.scala b/compiler/src/dotty/tools/io/ZipArchive.scala index a23bde8faaed..1ee79bd8036a 100644 --- a/compiler/src/dotty/tools/io/ZipArchive.scala +++ b/compiler/src/dotty/tools/io/ZipArchive.scala @@ -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 diff --git a/compiler/test/dotty/tools/dotc/core/tasty/PathPicklingTest.scala b/compiler/test/dotty/tools/dotc/core/tasty/PathPicklingTest.scala index 326a2dc87b2a..12d8425a32d6 100644 --- a/compiler/test/dotty/tools/dotc/core/tasty/PathPicklingTest.scala +++ b/compiler/test/dotty/tools/dotc/core/tasty/PathPicklingTest.scala @@ -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() diff --git a/compiler/test/dotty/tools/utils.scala b/compiler/test/dotty/tools/utils.scala index 03e25630c421..14981e001d38 100644 --- a/compiler/test/dotty/tools/utils.scala +++ b/compiler/test/dotty/tools/utils.scala @@ -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 diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 12a53a19931d..35fbb6e5fb14 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -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}") @@ -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 => From 8fa6145306cbd64f8cd0cc26aa1d2746849a3f8b Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Tue, 20 May 2025 16:41:52 +0200 Subject: [PATCH 2/2] fix: add `using` keyword to avoid warning in 3.7.0 --- compiler/test/dotty/tools/dotc/SettingsTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/dotc/SettingsTests.scala b/compiler/test/dotty/tools/dotc/SettingsTests.scala index ec342db875a6..24549ade4d23 100644 --- a/compiler/test/dotty/tools/dotc/SettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala @@ -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(_)) @Test def `Output side effect is not present when setting is deprecated`: Unit = val result = Using.resource(Files.createTempFile("myfile", ".jar")){ file =>