From 222b3b1df656dd09aa94f21f2c65ec8440cb4f26 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Tue, 17 Sep 2024 21:07:38 +0200 Subject: [PATCH 1/4] Removed some nn and unsafeNulls --- compiler/src/dotty/tools/MainGenericCompiler.scala | 2 -- compiler/src/dotty/tools/backend/jvm/AsmUtils.scala | 2 -- .../src/dotty/tools/backend/jvm/PostProcessor.scala | 6 +++--- compiler/src/dotty/tools/dotc/Bench.scala | 2 +- compiler/src/dotty/tools/dotc/Run.scala | 2 +- compiler/src/dotty/tools/dotc/cc/CaptureSet.scala | 2 +- .../dotty/tools/dotc/config/CommandLineParser.scala | 2 +- compiler/src/dotty/tools/dotc/config/Printers.scala | 2 +- .../src/dotty/tools/dotc/config/ScalaSettings.scala | 1 - .../tools/dotc/config/ScalaSettingsProperties.scala | 1 - .../src/dotty/tools/dotc/config/ScalaVersion.scala | 10 ++++------ compiler/src/dotty/tools/dotc/config/Settings.scala | 2 -- .../src/dotty/tools/dotc/core/MacroClassLoader.scala | 2 -- compiler/src/dotty/tools/dotc/core/Names.scala | 2 +- compiler/src/dotty/tools/dotc/core/StdNames.scala | 2 +- compiler/src/dotty/tools/dotc/core/TypeErrors.scala | 2 +- .../tools/dotc/core/classfile/AbstractFileReader.scala | 2 -- compiler/src/dotty/tools/dotc/printing/Texts.scala | 2 +- .../dotty/tools/dotc/transform/GenericSignatures.scala | 4 ++-- .../main/dotty/tools/pc/CompilerSearchVisitor.scala | 2 +- .../dotty/tools/pc/SymbolInformationProvider.scala | 2 +- .../src/main/dotty/tools/pc/TastyUtils.scala | 2 +- project/Build.scala | 10 +++++----- 23 files changed, 26 insertions(+), 40 deletions(-) diff --git a/compiler/src/dotty/tools/MainGenericCompiler.scala b/compiler/src/dotty/tools/MainGenericCompiler.scala index aa924a237f73..2c3f6f97e79e 100644 --- a/compiler/src/dotty/tools/MainGenericCompiler.scala +++ b/compiler/src/dotty/tools/MainGenericCompiler.scala @@ -1,7 +1,5 @@ package dotty.tools -import scala.language.unsafeNulls - import scala.annotation.tailrec import scala.io.Source import scala.util.Try diff --git a/compiler/src/dotty/tools/backend/jvm/AsmUtils.scala b/compiler/src/dotty/tools/backend/jvm/AsmUtils.scala index e6393ce82054..8a71a09aa7ab 100644 --- a/compiler/src/dotty/tools/backend/jvm/AsmUtils.scala +++ b/compiler/src/dotty/tools/backend/jvm/AsmUtils.scala @@ -2,8 +2,6 @@ package dotty.tools package backend package jvm -import scala.language.unsafeNulls - import scala.tools.asm.tree.{AbstractInsnNode} import java.io.PrintWriter import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier} diff --git a/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala b/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala index 9f172806a3b5..6b0c935642b6 100644 --- a/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala +++ b/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala @@ -36,7 +36,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes: setInnerClasses(classNode) serializeClass(classNode) catch - case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.nn.contains("too large!") => + case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.contains("too large!") => backendReporting.error(em"Could not write class $internalName because it exceeds JVM code size limits. ${e.getMessage}") null case ex: Throwable => @@ -58,8 +58,8 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes: } private def warnCaseInsensitiveOverwrite(clazz: GeneratedClass) = { - val name = clazz.classNode.name.nn - val lowerCaseJavaName = name.nn.toLowerCase + val name = clazz.classNode.name + val lowerCaseJavaName = name.toLowerCase val clsPos = clazz.position caseInsensitively.putIfAbsent(lowerCaseJavaName, (name, clsPos)) match { case null => () diff --git a/compiler/src/dotty/tools/dotc/Bench.scala b/compiler/src/dotty/tools/dotc/Bench.scala index cbc490919cfe..26259dcaa28b 100644 --- a/compiler/src/dotty/tools/dotc/Bench.scala +++ b/compiler/src/dotty/tools/dotc/Bench.scala @@ -30,7 +30,7 @@ object Bench extends Driver: println(s"time elapsed: ${times(curRun)}ms") if ctx.settings.Xprompt.value || waitAfter == curRun + 1 then print("hit to continue >") - System.in.nn.read() + System.in.read() reporter def extractNumArg(args: Array[String], name: String, default: Int = 1): (Int, Array[String]) = { diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 50fd668c7696..2a6ba0da014a 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -211,7 +211,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint try trackProgress(_.cancel()) finally - Thread.currentThread().nn.interrupt() + Thread.currentThread().interrupt() private def doAdvancePhase(currentPhase: Phase, wasRan: Boolean)(using Context): Unit = trackProgress: progress => diff --git a/compiler/src/dotty/tools/dotc/cc/CaptureSet.scala b/compiler/src/dotty/tools/dotc/cc/CaptureSet.scala index 81b4287961ba..fd16312b0a85 100644 --- a/compiler/src/dotty/tools/dotc/cc/CaptureSet.scala +++ b/compiler/src/dotty/tools/dotc/cc/CaptureSet.scala @@ -634,7 +634,7 @@ object CaptureSet: // For debugging: A trace where a set was created. Note that logically it would make more // sense to place this variable in Mapped, but that runs afoul of the initializatuon checker. - val stack = if debugSets && this.isInstanceOf[Mapped] then (new Throwable).getStackTrace().nn.take(20) else null + val stack = if debugSets && this.isInstanceOf[Mapped] then (new Throwable).getStackTrace().take(20) else null /** The variable from which this variable is derived */ def source: Var diff --git a/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala b/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala index 2e76561c9913..855c0410042a 100644 --- a/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala +++ b/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala @@ -114,7 +114,7 @@ object CommandLineParser: def expandArg(arg: String): List[String] = val path = Paths.get(arg.stripPrefix("@")) if !Files.exists(path) then - System.err.nn.println(s"Argument file ${path.nn.getFileName} could not be found") + System.err.println(s"Argument file ${path.getFileName} could not be found") Nil else def stripComment(s: String) = s.indexOf('#') match { case -1 => s case i => s.substring(0, i) } diff --git a/compiler/src/dotty/tools/dotc/config/Printers.scala b/compiler/src/dotty/tools/dotc/config/Printers.scala index 81fd60497025..4c66e1cdf833 100644 --- a/compiler/src/dotty/tools/dotc/config/Printers.scala +++ b/compiler/src/dotty/tools/dotc/config/Printers.scala @@ -5,7 +5,7 @@ import core.Contexts.{Context, ctx} object Printers { class Printer { - def println(msg: => String): Unit = System.out.nn.println(msg) + def println(msg: => String): Unit = System.out.println(msg) } object noPrinter extends Printer { diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 6ef33d24f8be..53845704e01e 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -1,7 +1,6 @@ package dotty.tools.dotc package config -import scala.language.unsafeNulls import dotty.tools.dotc.config.PathResolver.Defaults import dotty.tools.dotc.config.Settings.{Setting, SettingGroup, SettingCategory, Deprecation} import dotty.tools.dotc.config.SourceVersion diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala index e42d2d53529e..5928ba40b16c 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala @@ -4,7 +4,6 @@ package config import Settings.Setting.ChoiceWithHelp import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile} -import scala.language.unsafeNulls object ScalaSettingsProperties: diff --git a/compiler/src/dotty/tools/dotc/config/ScalaVersion.scala b/compiler/src/dotty/tools/dotc/config/ScalaVersion.scala index 9f603e6792be..a9fffa7a3bb6 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaVersion.scala @@ -3,8 +3,6 @@ package dotty.tools package dotc.config -import scala.language.unsafeNulls - import scala.annotation.internal.sharable import scala.util.{Try, Success, Failure} @@ -82,20 +80,20 @@ case class SpecificScalaVersion(major: Int, minor: Int, rev: Int, build: ScalaBu "The minor and revision parts are optional." )) - def toInt(s: String) = s match { + def toInt(s: String | Null) = s match { case null | "" => 0 - case _ => s.toInt + case _ => s.nn.toInt } def isInt(s: String) = Try(toInt(s)).isSuccess import ScalaBuild.* - def toBuild(s: String) = s match { + def toBuild(s: String | Null) = s match { case null | "FINAL" => Final case s if (s.toUpperCase.startsWith("RC") && isInt(s.substring(2))) => RC(toInt(s.substring(2))) case s if (s.toUpperCase.startsWith("M") && isInt(s.substring(1))) => Milestone(toInt(s.substring(1))) - case _ => Development(s) + case _ => Development(s.nn) } try versionString match { diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index f85f2cc57de4..7842113b5e48 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -1,8 +1,6 @@ package dotty.tools.dotc package config -import scala.language.unsafeNulls - import core.Contexts.* import dotty.tools.io.{AbstractFile, Directory, JarArchive, PlainDirectory} diff --git a/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala b/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala index b6b316ac14d9..c4c41a460a70 100644 --- a/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala +++ b/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala @@ -19,8 +19,6 @@ object MacroClassLoader { ctx.setProperty(MacroClassLoaderKey, makeMacroClassLoader(using ctx)) private def makeMacroClassLoader(using Context): ClassLoader = trace("new macro class loader") { - import scala.language.unsafeNulls - val entries = ClassPath.expandPath(ctx.settings.classpath.value, expandStar=true) val urls = entries.map(cp => java.nio.file.Paths.get(cp).toUri.toURL).toArray val out = Option(ctx.settings.outputDir.value.toURL) // to find classes in case of suspended compilation diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index 3f9667b08067..8c8ff07efd5e 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -393,7 +393,7 @@ object Names { // because asserts are caught in exception handlers which might // cause other failures. In that case the first, important failure // is lost. - System.err.nn.println("Backend should not call Name#toString, Name#mangledString should be used instead.") + System.err.println("Backend should not call Name#toString, Name#mangledString should be used instead.") Thread.dumpStack() assert(false) } diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index d3e198a7e7a7..a981f942016c 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -42,7 +42,7 @@ object StdNames { @sharable private val disallowed = java.util.regex.Pattern.compile("""[<>]""").nn - def sanitize(str: String): String = disallowed.matcher(str).nn.replaceAll("""\$""").nn + def sanitize(str: String): String = disallowed.matcher(str).replaceAll("""\$""").nn } abstract class DefinedNames[N <: Name] { diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index 1c9696da67d1..a65c0ada0c24 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -246,7 +246,7 @@ class UnpicklingError(denot: Denotation, where: String, cause: Throwable)(using case cause: UnpicklingError => "" case _ => if ctx.settings.YdebugUnpickling.value then - cause.getStackTrace().nn.mkString("\n ", "\n ", "") + cause.getStackTrace().mkString("\n ", "\n ", "") else "\n\nRun with -Ydebug-unpickling to see full stack trace." em"""Could not read definition $denot$where. Caused by the following exception: |$cause$debugUnpickling""" diff --git a/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala b/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala index 46581d00714e..d4f781e22126 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/AbstractFileReader.scala @@ -3,8 +3,6 @@ package dotc package core package classfile -import scala.language.unsafeNulls - import java.lang.Float.intBitsToFloat import java.lang.Double.longBitsToDouble import java.io.{ByteArrayInputStream, DataInputStream} diff --git a/compiler/src/dotty/tools/dotc/printing/Texts.scala b/compiler/src/dotty/tools/dotc/printing/Texts.scala index 475e2c6900d5..4db0c83fed58 100644 --- a/compiler/src/dotty/tools/dotc/printing/Texts.scala +++ b/compiler/src/dotty/tools/dotc/printing/Texts.scala @@ -74,7 +74,7 @@ object Texts { else appendIndented(that)(width) private def lengthWithoutAnsi(str: String): Int = - ansi.matcher(str).nn.replaceAll("").nn.length + ansi.matcher(str).replaceAll("").length def layout(width: Int): Text = this match { case Str(s, _) => diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index 1798d938272c..26ede05ba607 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -171,7 +171,7 @@ object GenericSignatures { def fullNameInSig(sym: Symbol): Unit = { assert(sym.isClass) val name = atPhase(genBCodePhase) { sanitizeName(sym.fullName).replace('.', '/') } - builder.append('L').nn.append(name) + builder.append('L').append(name) } def classSig(sym: Symbol, pre: Type = NoType, args: List[Type] = Nil): Unit = { @@ -216,7 +216,7 @@ object GenericSignatures { // TODO revisit this. Does it align with javac for code that can be expressed in both languages? val delimiter = if (builder.charAt(builder.length() - 1) == '>') '.' else '$' - builder.append(delimiter).nn.append(sanitizeName(sym.name)) + builder.append(delimiter).append(sanitizeName(sym.name)) } else fullNameInSig(sym) } diff --git a/presentation-compiler/src/main/dotty/tools/pc/CompilerSearchVisitor.scala b/presentation-compiler/src/main/dotty/tools/pc/CompilerSearchVisitor.scala index 9fb84ee1f513..d282d7c8a8f3 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/CompilerSearchVisitor.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/CompilerSearchVisitor.scala @@ -105,6 +105,6 @@ class CompilerSearchVisitor( override def isCancelled: Boolean = false private def normalizePackage(pkg: String): String = - pkg.replace("/", ".").nn.stripSuffix(".") + pkg.replace("/", ".").stripSuffix(".") end CompilerSearchVisitor diff --git a/presentation-compiler/src/main/dotty/tools/pc/SymbolInformationProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/SymbolInformationProvider.scala index ccda618078b8..0c08ed63ffe8 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/SymbolInformationProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/SymbolInformationProvider.scala @@ -105,7 +105,7 @@ object SymbolProvider: catch case NonFatal(e) => Nil private def normalizePackage(pkg: String): String = - pkg.replace("/", ".").nn.stripSuffix(".") + pkg.replace("/", ".").stripSuffix(".") private def toSymbols(info: SymbolInfo.SymbolParts)(using Context): List[Symbol] = def collectSymbols(denotation: Denotation): List[Symbol] = diff --git a/presentation-compiler/src/main/dotty/tools/pc/TastyUtils.scala b/presentation-compiler/src/main/dotty/tools/pc/TastyUtils.scala index 62a947aeb50b..0c2afad5f92a 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/TastyUtils.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/TastyUtils.scala @@ -40,7 +40,7 @@ object TastyUtils: end htmlTasty private def tastyHtmlPageTitle(file: URI) = - val filename = Paths.get(file).nn.getFileName().toString + val filename = Paths.get(file).getFileName().toString s"TASTy for $filename" private val standaloneHtmlStyles = diff --git a/project/Build.scala b/project/Build.scala index 49d990b639c4..7b097ebabdd9 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1036,7 +1036,7 @@ object Build { // compiler is updated. // Then, the next step is to enable flexible types by default and reduce the use of // `unsafeNulls`. - scalacOptions ++= Seq("-Yno-flexible-types"), + // scalacOptions ++= Seq("-Yno-flexible-types"), packageAll := { (`scala3-compiler` / packageAll).value ++ Seq( "scala3-compiler" -> (Compile / packageBin).value.getAbsolutePath, @@ -1428,10 +1428,10 @@ object Build { .dependsOn(`scala3-compiler-bootstrapped`, `scala3-library-bootstrapped`) .settings(presentationCompilerSettings) .settings(scala3PresentationCompilerBuildInfo) - .settings( - // Add `-Yno-flexible-types` flag for bootstrap, see comments for `bootstrappedDottyCompilerSettings` - Compile / scalacOptions += "-Yno-flexible-types" - ) + // .settings( + // // Add `-Yno-flexible-types` flag for bootstrap, see comments for `bootstrappedDottyCompilerSettings` + // Compile / scalacOptions += "-Yno-flexible-types" + // ) def scala3PresentationCompilerBuildInfo = Seq( From 65ace2b9bf708e1809cc1057be50aab05f1882fb Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Wed, 18 Sep 2024 16:36:02 +0200 Subject: [PATCH 2/4] Remove more .nn --- compiler/src/dotty/tools/dotc/core/NameOps.scala | 2 +- compiler/src/dotty/tools/dotc/core/Names.scala | 4 ++-- .../src/dotty/tools/dotc/parsing/JavaScanners.scala | 2 +- compiler/src/dotty/tools/dotc/report.scala | 4 ++-- .../tools/dotc/transform/InstrumentCoverage.scala | 10 +++++----- .../src/dotty/tools/dotc/transform/TreeChecker.scala | 2 +- .../src/dotty/tools/dotc/util/ParsedComment.scala | 2 -- compiler/src/dotty/tools/io/File.scala | 2 -- compiler/src/dotty/tools/io/FileWriters.scala | 2 +- .../dotty/tools/coursier/CoursierScalaTests.scala | 2 +- .../dotc/transform/PatmatExhaustivityTest.scala | 2 +- library/src/scala/runtime/LazyVals.scala | 2 +- library/src/scala/runtime/coverage/Invoker.scala | 2 +- library/src/scala/util/FromDigits.scala | 2 +- .../pc/completions/AmmoniteFileCompletions.scala | 12 ++++++------ 15 files changed, 24 insertions(+), 28 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 415aa049c587..544718508e9e 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -45,7 +45,7 @@ object NameOps { val cs = s.toArray val bytes = Codec.toUTF8(CharBuffer.wrap(cs).nn) md5.update(bytes) - val md5chars = md5.digest().nn.map(b => (b & 0xFF).toHexString).mkString + val md5chars = md5.digest().map(b => (b & 0xFF).toHexString).mkString prefix + marker + md5chars + marker + suffix } diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index 8c8ff07efd5e..baf95b9306d3 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -404,8 +404,8 @@ object Names { * from GenBCode or it also contains one of the whitelisted methods below. */ private def toStringOK = { - val trace: Array[StackTraceElement] = Thread.currentThread.nn.getStackTrace.asInstanceOf[Array[StackTraceElement]] - !trace.exists(_.getClassName.nn.endsWith("GenBCode")) || + val trace: Array[StackTraceElement] = Thread.currentThread.getStackTrace.asInstanceOf[Array[StackTraceElement]] + !trace.exists(_.getClassName.endsWith("GenBCode")) || trace.exists(elem => List( "mangledString", diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala b/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala index 3f993195e4f3..64f586ca0410 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala @@ -666,7 +666,7 @@ object JavaScanners { val limit: Double = if (token == DOUBLELIT) Double.MaxValue else Float.MaxValue try { - val value: Double = java.lang.Double.valueOf(strVal.toString).nn.doubleValue() + val value: Double = java.lang.Double.valueOf(strVal.toString).doubleValue() if (value > limit) error(em"floating point number too large") if (negated) -value else value diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 2ccf918e12fa..e149b287424e 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -84,8 +84,8 @@ object report: def bestEffortError(ex: Throwable, msg: String)(using Context): Unit = val stackTrace = Option(ex.getStackTrace()).map { st => - if st.nn.isEmpty then "" - else s"Stack trace: \n ${st.nn.mkString("\n ")}".stripMargin + if st.isEmpty then "" + else s"Stack trace: \n ${st.mkString("\n ")}".stripMargin }.getOrElse("") // Build tools and dotty's test framework may check precisely for // "Unsuccessful best-effort compilation." error text. diff --git a/compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala b/compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala index f5e0f8c63b58..a89e03f4fa6e 100644 --- a/compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala +++ b/compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala @@ -56,9 +56,9 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer: if !newlyCreated then // If the directory existed before, let's clean it up. - dataDir.listFiles.nn - .filter(_.nn.getName.nn.startsWith("scoverage")) - .foreach(_.nn.delete()) + dataDir.listFiles + .filter(_.getName.startsWith("scoverage")) + .foreach(_.delete()) end if coverageExcludeClasslikePatterns = ctx.settings.coverageExcludeClasslikes.value.map(_.r.pattern) @@ -71,13 +71,13 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer: private def isClassIncluded(sym: Symbol)(using Context): Boolean = val fqn = sym.fullName.toText(ctx.printerFn(ctx)).show coverageExcludeClasslikePatterns.isEmpty || !coverageExcludeClasslikePatterns.exists( - _.matcher(fqn).nn.matches + _.matcher(fqn).matches ) private def isFileIncluded(file: SourceFile)(using Context): Boolean = val normalizedPath = file.path.replace(".scala", "") coverageExcludeFilePatterns.isEmpty || !coverageExcludeFilePatterns.exists( - _.matcher(normalizedPath).nn.matches + _.matcher(normalizedPath).matches ) override protected def newTransformer(using Context) = diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index c35dc80c04a5..79f2133ac451 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -860,7 +860,7 @@ object TreeChecker { val stack = if !ctx.settings.Ydebug.value then "\nstacktrace available when compiling with `-Ydebug`" else if err.getStackTrace == null then " no stacktrace" - else err.getStackTrace.nn.mkString(" ", " \n", "") + else err.getStackTrace.mkString(" ", " \n", "") report.error( em"""Malformed tree was found while expanding macro with -Xcheck-macros. diff --git a/compiler/src/dotty/tools/dotc/util/ParsedComment.scala b/compiler/src/dotty/tools/dotc/util/ParsedComment.scala index ee56a74d5eb5..acced8dd857c 100644 --- a/compiler/src/dotty/tools/dotc/util/ParsedComment.scala +++ b/compiler/src/dotty/tools/dotc/util/ParsedComment.scala @@ -1,7 +1,5 @@ package dotty.tools.dotc.util -import scala.language.unsafeNulls - import dotty.tools.dotc.core.Comments.{Comment, docCtx} import dotty.tools.dotc.core.Contexts.* import dotty.tools.dotc.core.Names.TermName diff --git a/compiler/src/dotty/tools/io/File.scala b/compiler/src/dotty/tools/io/File.scala index 59e4a2ee451b..ea48966de6fb 100644 --- a/compiler/src/dotty/tools/io/File.scala +++ b/compiler/src/dotty/tools/io/File.scala @@ -8,8 +8,6 @@ package dotty.tools.io -import scala.language.unsafeNulls - import java.io.{File => JavaIoFile, _} import java.nio.file.{Files, Paths} import java.nio.file.StandardOpenOption.* diff --git a/compiler/src/dotty/tools/io/FileWriters.scala b/compiler/src/dotty/tools/io/FileWriters.scala index 5fdf43cfe8e3..38bca796373e 100644 --- a/compiler/src/dotty/tools/io/FileWriters.scala +++ b/compiler/src/dotty/tools/io/FileWriters.scala @@ -66,7 +66,7 @@ object FileWriters { def warning(message: Context ?=> Message): Unit = warning(message, NoSourcePosition) final def exception(reason: Context ?=> Message, throwable: Throwable): Unit = error({ - val trace = throwable.getStackTrace().nn.mkString("\n ") + val trace = throwable.getStackTrace().mkString("\n ") em"An unhandled exception was thrown in the compiler while\n ${reason.message}.\n${throwable}\n $trace" }, NoSourcePosition) } diff --git a/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala b/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala index 86b22009d15a..f44774141947 100644 --- a/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala +++ b/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala @@ -159,7 +159,7 @@ object CoursierScalaTests: def csScalaCmd(options: String*): List[String] = csScalaCmdWithStdin(options, None) - + def csScalaCmdWithStdin(options: Seq[String], stdin: Option[String]): List[String] = csCmd("dotty.tools.MainGenericRunner", options, stdin) diff --git a/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala b/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala index 4ed59db5c10e..70f26dfd104e 100644 --- a/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala +++ b/compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala @@ -35,7 +35,7 @@ class PatmatExhaustivityTest { e.printStackTrace(printWriter) } - stringBuffer.toString.trim.nn.replaceAll("\\s+\n", "\n") match { + stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match { case "" => Nil case s => s.linesIterator.toSeq } diff --git a/library/src/scala/runtime/LazyVals.scala b/library/src/scala/runtime/LazyVals.scala index 15220ea2410a..5d4c508d2076 100644 --- a/library/src/scala/runtime/LazyVals.scala +++ b/library/src/scala/runtime/LazyVals.scala @@ -26,7 +26,7 @@ object LazyVals { } private val base: Int = { - val processors = java.lang.Runtime.getRuntime.nn.availableProcessors() + val processors = java.lang.Runtime.getRuntime.availableProcessors() 8 * processors * processors } diff --git a/library/src/scala/runtime/coverage/Invoker.scala b/library/src/scala/runtime/coverage/Invoker.scala index c35c6c2ec7df..b2159e6873f6 100644 --- a/library/src/scala/runtime/coverage/Invoker.scala +++ b/library/src/scala/runtime/coverage/Invoker.scala @@ -51,6 +51,6 @@ object Invoker { @nowarn("cat=deprecation") def measurementFile(dataDir: String): File = new File( dataDir, - MeasurementsPrefix + runtimeUUID + "." + Thread.currentThread.nn.getId + MeasurementsPrefix + runtimeUUID + "." + Thread.currentThread.getId ) } diff --git a/library/src/scala/util/FromDigits.scala b/library/src/scala/util/FromDigits.scala index cb73782829ff..44532649868d 100644 --- a/library/src/scala/util/FromDigits.scala +++ b/library/src/scala/util/FromDigits.scala @@ -135,7 +135,7 @@ object FromDigits { case ex: NumberFormatException => throw MalformedNumber() } if (x.isInfinite) throw NumberTooLarge() - if (x == 0.0f && !zeroFloat.pattern.matcher(digits).nn.matches) throw NumberTooSmall() + if (x == 0.0f && !zeroFloat.pattern.matcher(digits).matches) throw NumberTooSmall() x } diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteFileCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteFileCompletions.scala index 81337c7d8dcb..a903aa5dea19 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteFileCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteFileCompletions.scala @@ -39,10 +39,10 @@ object AmmoniteFileCompletions: rawFileName: String )(using Context): List[CompletionValue] = val fileName: Option[String] = Option(rawFileName) - .flatMap(_.split("/").nn.lastOption.map(_.nn.stripSuffix(".amm.sc.scala"))) + .flatMap(_.split("/").lastOption.map(_.stripSuffix(".amm.sc.scala"))) val split: List[String] = Option(rawPath) - .fold(Nil)(_.split("\\$file").nn.toList.map(_.nn)) + .fold(Nil)(_.split("\\$file").toList.map(_.nn)) val editRange = selector.headOption.map { sel => if sel.sourcePos.span.isZeroExtent then posRange @@ -71,10 +71,10 @@ object AmmoniteFileCompletions: // drop / or \ val current = workspace.resolve(script.drop(1)) val importPath = translateImportToPath(select).drop(1) - val currentPath = current.nn.getParent().nn.resolve(importPath).nn.toAbsolutePath() + val currentPath = current.getParent().resolve(importPath).toAbsolutePath() val parentTextEdit = - if query.exists(_.nn.isEmpty()) && - Files.exists(currentPath.nn.getParent()) && Files.isDirectory( + if query.exists(_.isEmpty()) && + Files.exists(currentPath.getParent()) && Files.isDirectory( currentPath ) then List(parent) @@ -84,7 +84,7 @@ object AmmoniteFileCompletions: .iterator().nn .asScala .toList - .filter(path => !fileName.contains(path.nn.getFileName().toString.stripSuffix(".sc"))) + .filter(path => !fileName.contains(path.getFileName().toString.stripSuffix(".sc"))) .collect { case file if matches(file) => CompletionValue.FileSystemMember( From 3852f8d70dee31c3d99a4b6ddbf22fbd88d24d49 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 23 Sep 2024 14:57:56 +0200 Subject: [PATCH 3/4] Remove more .nn --- .../dotty/tools/backend/jvm/ClassfileWriters.scala | 14 ++++++-------- compiler/src/dotty/tools/dotc/Driver.scala | 4 ++-- .../src/dotty/tools/dotc/cc/CheckCaptures.scala | 2 +- .../tools/dotc/classpath/ClassPathFactory.scala | 2 +- .../tools/dotc/config/CommandLineParser.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/Comments.scala | 2 -- .../src/dotty/tools/dotc/core/Decorators.scala | 6 +++--- compiler/src/dotty/tools/dotc/core/NameOps.scala | 4 ++-- .../src/dotty/tools/dotc/core/TypeErrors.scala | 2 +- compiler/src/dotty/tools/dotc/core/TypeEval.scala | 2 +- .../tools/dotc/core/tasty/AttributeUnpickler.scala | 1 - .../dotty/tools/dotc/core/tasty/TastyPrinter.scala | 2 +- .../src/dotty/tools/dotc/plugins/Plugins.scala | 12 ++++-------- .../dotty/tools/dotc/printing/PlainPrinter.scala | 6 +++--- .../src/dotty/tools/dotc/printing/Showable.scala | 2 +- compiler/src/dotty/tools/dotc/printing/Texts.scala | 2 +- .../src/dotty/tools/dotc/quoted/Interpreter.scala | 2 -- .../src/dotty/tools/dotc/reporting/messages.scala | 2 +- .../src/dotty/tools/dotc/semanticdb/Scala3.scala | 2 +- .../src/dotty/tools/dotc/transform/Pickler.scala | 8 ++++---- .../dotty/tools/dotc/transform/init/Errors.scala | 2 +- .../dotty/tools/dotc/transform/init/Trace.scala | 6 +++--- .../dotc/transform/localopt/FormatChecker.scala | 2 +- .../tools/dotc/transform/sjs/PrepJSInterop.scala | 2 +- .../src/dotty/tools/dotc/typer/RefChecks.scala | 4 ++-- .../src/dotty/tools/dotc/util/ShowPickled.scala | 2 +- compiler/src/dotty/tools/io/FileWriters.scala | 6 +++--- compiler/src/dotty/tools/io/Path.scala | 4 +--- .../quoted/runtime/impl/printers/SourceCode.scala | 2 +- .../dotty/tools/backend/jvm/StringConcatTest.scala | 2 +- compiler/test/dotty/tools/dotc/SettingsTests.scala | 8 +++----- .../test/dotty/tools/dotc/TupleShowTests.scala | 2 +- .../dotc/core/tasty/TastyHeaderUnpicklerTest.scala | 4 ++-- 33 files changed, 56 insertions(+), 71 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala b/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala index e2730c1e84ab..e2ce73f79028 100644 --- a/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala +++ b/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala @@ -18,8 +18,6 @@ import BTypes.InternalName import scala.util.chaining.* import dotty.tools.io.JarArchive -import scala.language.unsafeNulls - /** !!! This file is now copied in `dotty.tools.io.FileWriters` in a more general way that does not rely upon * `PostProcessorFrontendAccess`, this should probably be changed to wrap that class instead. * @@ -54,11 +52,11 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) { def close(): Unit protected def classRelativePath(className: InternalName, suffix: String = ".class"): String = - className.replace('.', '/').nn + suffix + className.replace('.', '/') + suffix } object ClassfileWriter { - private def getDirectory(dir: String): Path = Paths.get(dir).nn + private def getDirectory(dir: String): Path = Paths.get(dir) def apply(): ClassfileWriter = { val jarManifestMainClass: Option[String] = compilerSettings.mainClass.orElse { @@ -137,7 +135,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) { new JarEntryWriter(jarFile, jarManifestMainClass, jarCompressionLevel) } else if (file.isVirtual) new VirtualFileWriter(file) - else if (file.isDirectory) new DirEntryWriter(file.file.toPath.nn) + else if (file.isDirectory) new DirEntryWriter(file.file.toPath) else throw new IllegalStateException(s"don't know how to handle an output of $file [${file.getClass}]") } @@ -151,7 +149,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) { val jarWriter: JarOutputStream = { import scala.util.Properties.* val manifest = new Manifest - val attrs = manifest.getMainAttributes.nn + val attrs = manifest.getMainAttributes attrs.put(MANIFEST_VERSION, "1.0") attrs.put(ScalaCompilerVersion, versionNumberString) mainClass.foreach(c => attrs.put(MAIN_CLASS, c)) @@ -184,7 +182,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) { // important detail here, even on Windows, Zinc expects the separator within the jar // to be the system default, (even if in the actual jar file the entry always uses '/'). // see https://github.com/sbt/zinc/blob/dcddc1f9cfe542d738582c43f4840e17c053ce81/internal/compiler-bridge/src/main/scala/xsbt/JarUtils.scala#L47 - val pathInJar = + val pathInJar = if File.separatorChar == '/' then relativePath else relativePath.replace('/', File.separatorChar) PlainFile.toPlainFile(Paths.get(s"${file.absolutePath}!$pathInJar")) @@ -293,5 +291,5 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) { } /** Can't output a file due to the state of the file system. */ - class FileConflictException(msg: String, cause: Throwable = null) extends IOException(msg, cause) + class FileConflictException(msg: String, cause: Throwable | Null = null) extends IOException(msg, cause) } diff --git a/compiler/src/dotty/tools/dotc/Driver.scala b/compiler/src/dotty/tools/dotc/Driver.scala index 98abe2ac6c38..a401bb689db0 100644 --- a/compiler/src/dotty/tools/dotc/Driver.scala +++ b/compiler/src/dotty/tools/dotc/Driver.scala @@ -38,7 +38,7 @@ class Driver { finish(compiler, run) catch case ex: FatalError => - report.error(ex.getMessage.nn) // signals that we should fail compilation. + report.error(ex.getMessage) // signals that we should fail compilation. case ex: Throwable if ctx.usedBestEffortTasty => report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.") throw ex @@ -117,7 +117,7 @@ class Driver { .distinct val ctx1 = ctx.fresh val fullClassPath = - (newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator.nn) + (newEntries :+ ctx.settings.classpath.value).mkString(java.io.File.pathSeparator) ctx1.setSetting(ctx1.settings.classpath, fullClassPath) else ctx diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index 4d905a5df4ab..4b3b9b86b610 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -991,7 +991,7 @@ class CheckCaptures extends Recheck, SymTransformer: trace.force(i"rechecking $tree with pt = $pt", recheckr, show = true): super.recheck(tree, pt) catch case ex: NoCommonRoot => - report.error(ex.getMessage.nn) + report.error(ex.getMessage) tree.tpe finally curEnv = saved if tree.isTerm then diff --git a/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala b/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala index 080f8d4e63d2..416bcc85a783 100644 --- a/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala +++ b/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala @@ -67,7 +67,7 @@ class ClassPathFactory { for file <- files a <- ClassPath.expandManifestPath(file.absolutePath) - path = java.nio.file.Paths.get(a.toURI()).nn + path = java.nio.file.Paths.get(a.toURI()) if Files.exists(path) yield newClassPath(AbstractFile.getFile(path)) diff --git a/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala b/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala index 855c0410042a..50aa89779f50 100644 --- a/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala +++ b/compiler/src/dotty/tools/dotc/config/CommandLineParser.scala @@ -118,8 +118,8 @@ object CommandLineParser: Nil else def stripComment(s: String) = s.indexOf('#') match { case -1 => s case i => s.substring(0, i) } - val lines = Files.readAllLines(path).nn - val params = lines.asScala.map(stripComment).filter(!_.nn.isEmpty).mkString(" ") + val lines = Files.readAllLines(path) + val params = lines.asScala.map(stripComment).filter(!_.isEmpty).mkString(" ") tokenize(params) class ParseException(msg: String) extends RuntimeException(msg) diff --git a/compiler/src/dotty/tools/dotc/core/Comments.scala b/compiler/src/dotty/tools/dotc/core/Comments.scala index 92160c97973d..5ee1d5856605 100644 --- a/compiler/src/dotty/tools/dotc/core/Comments.scala +++ b/compiler/src/dotty/tools/dotc/core/Comments.scala @@ -2,8 +2,6 @@ package dotty.tools package dotc package core -import scala.language.unsafeNulls - import ast.{ untpd, tpd } import Symbols.*, Contexts.* import util.{SourceFile, ReadOnlyMap} diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 29d4b3fa4052..765fbd2907fc 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -51,7 +51,7 @@ object Decorators { if name.length != 0 then name.getChars(0, name.length, chars, s.length) termName(chars, 0, len) case name: TypeName => s.concat(name.toTermName) - case _ => termName(s.concat(name.toString).nn) + case _ => termName(s.concat(name.toString)) def indented(width: Int): String = val padding = " " * width @@ -289,10 +289,10 @@ object Decorators { case NonFatal(ex) if !ctx.settings.YshowPrintErrors.value => s"... (cannot display due to ${ex.className} ${ex.getMessage}) ..." - case _ => String.valueOf(x).nn + case _ => String.valueOf(x) /** Returns the simple class name of `x`. */ - def className: String = x.getClass.getSimpleName.nn + def className: String = x.getClass.getSimpleName extension [T](x: T) def assertingErrorsReported(using Context): T = { diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 544718508e9e..ce726785e7e7 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -15,7 +15,7 @@ import nme.* object NameOps { object compactify { - lazy val md5: MessageDigest = MessageDigest.getInstance("MD5").nn + lazy val md5: MessageDigest = MessageDigest.getInstance("MD5") inline val CLASSFILE_NAME_CHAR_LIMIT = 240 @@ -43,7 +43,7 @@ object NameOps { val suffix = s.takeRight(edge) val cs = s.toArray - val bytes = Codec.toUTF8(CharBuffer.wrap(cs).nn) + val bytes = Codec.toUTF8(CharBuffer.wrap(cs)) md5.update(bytes) val md5chars = md5.digest().map(b => (b & 0xFF).toHexString).mkString diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index a65c0ada0c24..ce14cad6871c 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -32,7 +32,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""): || ctx.settings.YdebugCyclic.value override def fillInStackTrace(): Throwable = - if computeStackTrace then super.fillInStackTrace().nn + if computeStackTrace then super.fillInStackTrace() else this /** Convert to message. This takes an additional Context, so that we diff --git a/compiler/src/dotty/tools/dotc/core/TypeEval.scala b/compiler/src/dotty/tools/dotc/core/TypeEval.scala index 4d5496cff880..a6c308bb2a55 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeEval.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeEval.scala @@ -94,7 +94,7 @@ object TypeEval: val result = try op catch case e: Throwable => - throw TypeError(em"${e.getMessage.nn}") + throw TypeError(em"${e.getMessage}") ConstantType(Constant(result)) def fieldsOf: Option[Type] = diff --git a/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala index 43a2bea27216..c5770d69b002 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala @@ -1,7 +1,6 @@ package dotty.tools.dotc package core.tasty -import scala.language.unsafeNulls import scala.collection.immutable.BitSet import scala.collection.immutable.TreeMap diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala index 72f6895f122c..ee798e29721e 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala @@ -53,7 +53,7 @@ object TastyPrinter: else if arg.endsWith(".tasty") || (allowBetasty && arg.endsWith(".betasty")) then val path = Paths.get(arg) if Files.exists(path) then - printTasty(arg, Files.readAllBytes(path).nn, arg.endsWith(".betasty")) + printTasty(arg, Files.readAllBytes(path), arg.endsWith(".betasty")) else println("File not found: " + arg) System.exit(1) diff --git a/compiler/src/dotty/tools/dotc/plugins/Plugins.scala b/compiler/src/dotty/tools/dotc/plugins/Plugins.scala index a6672d475129..490d1683b304 100644 --- a/compiler/src/dotty/tools/dotc/plugins/Plugins.scala +++ b/compiler/src/dotty/tools/dotc/plugins/Plugins.scala @@ -1,8 +1,6 @@ package dotty.tools.dotc package plugins -import scala.language.unsafeNulls - import core.* import Contexts.* import Decorators.em @@ -47,13 +45,12 @@ trait Plugins { goods map (_.get) } - private var _roughPluginsList: List[Plugin] = uninitialized + private var _roughPluginsList: List[Plugin] | Null = null protected def roughPluginsList(using Context): List[Plugin] = if (_roughPluginsList == null) { _roughPluginsList = loadRoughPluginsList - _roughPluginsList } - else _roughPluginsList + _roughPluginsList.nn /** Load all available plugins. Skips plugins that * either have the same name as another one, or which @@ -99,13 +96,12 @@ trait Plugins { plugs } - private var _plugins: List[Plugin] = uninitialized + private var _plugins: List[Plugin] | Null = null def plugins(using Context): List[Plugin] = if (_plugins == null) { _plugins = loadPlugins - _plugins } - else _plugins + _plugins.nn /** A description of all the plugins that are loaded */ def pluginDescriptions(using Context): String = diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index cac82eb0c4bd..c5c3297697a7 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -394,7 +394,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp: ThisType => nameString(tp.cls) + ".this" case SuperType(thistpe: SingletonType, _) => - toTextRef(thistpe).map(_.replaceAll("""\bthis$""", "super").nn) + toTextRef(thistpe).map(_.replaceAll("""\bthis$""", "super")) case SuperType(thistpe, _) => "Super(" ~ toTextGlobal(thistpe) ~ ")" case tp @ ConstantType(value) => @@ -628,7 +628,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case '"' => "\\\"" case '\'' => "\\\'" case '\\' => "\\\\" - case _ => if ch.isControl then f"${"\\"}u${ch.toInt}%04x" else String.valueOf(ch).nn + case _ => if ch.isControl then f"${"\\"}u${ch.toInt}%04x" else String.valueOf(ch) } def toText(const: Constant): Text = const.tag match { @@ -638,7 +638,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case LongTag => literalText(const.longValue.toString + "L") case DoubleTag => literalText(const.doubleValue.toString + "d") case FloatTag => literalText(const.floatValue.toString + "f") - case _ => literalText(String.valueOf(const.value).nn) + case _ => literalText(String.valueOf(const.value)) } /** Usual target for `Annotation#toText`, overridden in RefinedPrinter */ diff --git a/compiler/src/dotty/tools/dotc/printing/Showable.scala b/compiler/src/dotty/tools/dotc/printing/Showable.scala index 4480aa9c76a4..490778a7413a 100644 --- a/compiler/src/dotty/tools/dotc/printing/Showable.scala +++ b/compiler/src/dotty/tools/dotc/printing/Showable.scala @@ -25,7 +25,7 @@ trait Showable extends Any { /** The string representation with each line after the first one indented * by the given given margin (in spaces). */ - def showIndented(margin: Int)(using Context): String = show.replace("\n", "\n" + " " * margin).nn + def showIndented(margin: Int)(using Context): String = show.replace("\n", "\n" + " " * margin) /** The summarized string representation of this showable element. * Recursion depth is limited to some smallish value. Default is diff --git a/compiler/src/dotty/tools/dotc/printing/Texts.scala b/compiler/src/dotty/tools/dotc/printing/Texts.scala index 4db0c83fed58..014765b63274 100644 --- a/compiler/src/dotty/tools/dotc/printing/Texts.scala +++ b/compiler/src/dotty/tools/dotc/printing/Texts.scala @@ -5,7 +5,7 @@ import scala.annotation.internal.sharable object Texts { @sharable - private val ansi = java.util.regex.Pattern.compile("\u001b\\[\\d+m").nn + private val ansi = java.util.regex.Pattern.compile("\u001b\\[\\d+m") sealed abstract class Text { diff --git a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala index e34d35065476..dbc2694dc891 100644 --- a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala +++ b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala @@ -1,8 +1,6 @@ package dotty.tools.dotc package quoted -import scala.language.unsafeNulls - import scala.collection.mutable import scala.reflect.ClassTag diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 3b7fba1cb52d..b986ac6c15b7 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -92,7 +92,7 @@ abstract class CyclicMsg(errorId: ErrorMessageID)(using Context) extends Message protected def debugInfo = if ctx.settings.YdebugCyclic.value then - "\n\nStacktrace:" ++ ex.getStackTrace().nn.mkString("\n ", "\n ", "") + "\n\nStacktrace:" ++ ex.getStackTrace().mkString("\n ", "\n ", "") else "\n\n Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace." protected def context: String = ex.optTrace match diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala index f49b00089712..a20a0d181a55 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala @@ -420,7 +420,7 @@ object Scala3: else Descriptor.None def unescapeUnicode = - unicodeEscape.replaceAllIn(symbol, m => String.valueOf(Integer.parseInt(m.group(1), 16).toChar).nn) + unicodeEscape.replaceAllIn(symbol, m => String.valueOf(Integer.parseInt(m.group(1), 16).toChar)) def isJavaIdent = symbol.nonEmpty && isJavaIdentifierStart(symbol.head) && symbol.tail.forall(isJavaIdentifierPart) diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index c8c071064ab8..108277599010 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -258,7 +258,7 @@ class Pickler extends Phase { } private def computeInternalName(cls: ClassSymbol)(using Context): String = - if cls.is(Module) then cls.binaryClassName.stripSuffix(str.MODULE_SUFFIX).nn + if cls.is(Module) then cls.binaryClassName.stripSuffix(str.MODULE_SUFFIX) else cls.binaryClassName override def run(using Context): Unit = { @@ -413,11 +413,11 @@ class Pickler extends Phase { ) if ctx.isBestEffort then val outpath = - ctx.settings.outputDir.value.jpath.toAbsolutePath.nn.normalize.nn - .resolve("META-INF").nn + ctx.settings.outputDir.value.jpath.toAbsolutePath.normalize + .resolve("META-INF") .resolve("best-effort") Files.createDirectories(outpath) - BestEffortTastyWriter.write(outpath.nn, result) + BestEffortTastyWriter.write(outpath, result) result } diff --git a/compiler/src/dotty/tools/dotc/transform/init/Errors.scala b/compiler/src/dotty/tools/dotc/transform/init/Errors.scala index 85feb609c90a..0b843b4b33fd 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Errors.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Errors.scala @@ -31,7 +31,7 @@ object Errors: report.warning(show, this.pos) end Error - override def toString() = this.getClass.getName.nn + override def toString() = this.getClass.getName /** Access non-initialized field */ case class AccessNonInit(field: Symbol)(val trace: Trace) extends Error: diff --git a/compiler/src/dotty/tools/dotc/transform/init/Trace.scala b/compiler/src/dotty/tools/dotc/transform/init/Trace.scala index ffaccad963af..9a00589197d5 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Trace.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Trace.scala @@ -51,7 +51,7 @@ object Trace: val line = if pos.source.exists then val loc = "[ " + pos.source.file.name + ":" + (pos.line + 1) + " ]" - val code = SyntaxHighlighting.highlight(pos.lineContent.trim.nn) + val code = SyntaxHighlighting.highlight(pos.lineContent.trim) i"$code\t$loc" else tree match @@ -59,7 +59,7 @@ object Trace: // The definition can be huge, avoid printing the whole definition. defDef.symbol.showFullName case _ => - tree.show.split(System.lineSeparator(), 2).nn.head.nn + tree.show.split(System.lineSeparator(), 2).head val positionMarkerLine = if pos.exists && pos.source.exists then @@ -86,7 +86,7 @@ object Trace: */ private def positionMarker(pos: SourcePosition): String = val trimmed = pos.source.lineContent(pos.start).takeWhile(c => c.isWhitespace).length - val padding = pos.startColumnPadding.substring(trimmed).nn + val padding = pos.startColumnPadding.substring(trimmed) val carets = if (pos.startLine == pos.endLine) "^" * math.max(1, pos.endColumn - pos.startColumn) diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/FormatChecker.scala b/compiler/src/dotty/tools/dotc/transform/localopt/FormatChecker.scala index 9e40792895c0..5ac96f58011b 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/FormatChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/FormatChecker.scala @@ -74,7 +74,7 @@ class TypedFormatChecker(partsElems: List[Tree], parts: List[String], args: List def loop(remaining: List[String], n: Int): Unit = remaining match case part0 :: more => - def badPart(t: Throwable): String = "".tap(_ => report.partError(t.getMessage.nn, index = n, offset = 0)) + def badPart(t: Throwable): String = "".tap(_ => report.partError(t.getMessage, index = n, offset = 0)) val part = try StringContext.processEscapes(part0) catch badPart val matches = formatPattern.findAllMatchIn(part) diff --git a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala index c7316482c193..13fcbe542448 100644 --- a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala +++ b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala @@ -651,7 +651,7 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP val dotIndex = pathName.indexOf('.') val globalRef = if (dotIndex < 0) pathName - else pathName.substring(0, dotIndex).nn + else pathName.substring(0, dotIndex) checkGlobalRefName(globalRef) } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 0a0356707048..c9cd2b05a94a 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1259,9 +1259,9 @@ object RefChecks { val matches = referencePattern.findAllIn(s) for reference <- matches do val referenceOffset = matches.start - val prefixlessReference = reference.replaceFirst("""\$\{\s*""", "").nn + val prefixlessReference = reference.replaceFirst("""\$\{\s*""", "") val variableOffset = referenceOffset + reference.length - prefixlessReference.length - val variableName = prefixlessReference.replaceFirst("""\s*\}""", "").nn + val variableName = prefixlessReference.replaceFirst("""\s*\}""", "") f(variableName, variableOffset) end checkImplicitNotFoundAnnotation diff --git a/compiler/src/dotty/tools/dotc/util/ShowPickled.scala b/compiler/src/dotty/tools/dotc/util/ShowPickled.scala index 8d5d0c27ab0e..15d553e703b3 100644 --- a/compiler/src/dotty/tools/dotc/util/ShowPickled.scala +++ b/compiler/src/dotty/tools/dotc/util/ShowPickled.scala @@ -113,7 +113,7 @@ object ShowPickled { result.toInt } - def printFile(buf: PickleBuffer, out: PrintStream = System.out.nn): Unit = { + def printFile(buf: PickleBuffer, out: PrintStream = System.out): Unit = { out.println("Version " + buf.readNat() + "." + buf.readNat()) val index = buf.createIndex val entryList = makeEntryList(buf, index) diff --git a/compiler/src/dotty/tools/io/FileWriters.scala b/compiler/src/dotty/tools/io/FileWriters.scala index 38bca796373e..849b80c5e745 100644 --- a/compiler/src/dotty/tools/io/FileWriters.scala +++ b/compiler/src/dotty/tools/io/FileWriters.scala @@ -189,7 +189,7 @@ object FileWriters { def close(): Unit protected def classToRelativePath(className: InternalName): String = - className.replace('.', '/').nn + ".tasty" + className.replace('.', '/') + ".tasty" } object TastyWriter { @@ -234,7 +234,7 @@ object FileWriters { new JarEntryWriter(jarFile, jarManifestMainClass, jarCompressionLevel) } else if (file.isVirtual) new VirtualFileWriter(file) - else if (file.isDirectory) new DirEntryWriter(file.file.toPath.nn) + else if (file.isDirectory) new DirEntryWriter(file.file.toPath) else throw new IllegalStateException(s"don't know how to handle an output of $file [${file.getClass}]") } @@ -248,7 +248,7 @@ object FileWriters { val jarWriter: JarOutputStream = { import scala.util.Properties.* val manifest = new Manifest - val attrs = manifest.getMainAttributes.nn + val attrs = manifest.getMainAttributes attrs.put(MANIFEST_VERSION, "1.0") attrs.put(ScalaCompilerVersion, versionNumberString) mainClass.foreach(c => attrs.put(MAIN_CLASS, c)) diff --git a/compiler/src/dotty/tools/io/Path.scala b/compiler/src/dotty/tools/io/Path.scala index 6f97e03ca4d7..39665395c289 100644 --- a/compiler/src/dotty/tools/io/Path.scala +++ b/compiler/src/dotty/tools/io/Path.scala @@ -5,8 +5,6 @@ package dotty.tools.io -import scala.language.unsafeNulls - import java.io.RandomAccessFile import java.nio.file.* import java.net.{URI, URL} @@ -46,7 +44,7 @@ object Path { def fileName(name: String): String = { val i = name.lastIndexOf('.') if (i < 0) name - else name.substring(0, i).nn + else name.substring(0, i) } def onlyDirs(xs: Iterator[Path]): Iterator[Directory] = xs.filter(_.isDirectory).map(_.toDirectory) diff --git a/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala b/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala index 64a0ff9db9ec..25c921f8561f 100644 --- a/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala +++ b/compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala @@ -1454,7 +1454,7 @@ object SourceCode { case '"' => "\\\"" case '\'' => "\\\'" case '\\' => "\\\\" - case _ => if ch.isControl then f"${"\\"}u${ch.toInt}%04x" else String.valueOf(ch).nn + case _ => if ch.isControl then f"${"\\"}u${ch.toInt}%04x" else String.valueOf(ch) } private def escapedString(str: String): String = str flatMap escapedChar diff --git a/compiler/test/dotty/tools/backend/jvm/StringConcatTest.scala b/compiler/test/dotty/tools/backend/jvm/StringConcatTest.scala index 14352106c5e8..613e72b32e52 100644 --- a/compiler/test/dotty/tools/backend/jvm/StringConcatTest.scala +++ b/compiler/test/dotty/tools/backend/jvm/StringConcatTest.scala @@ -122,7 +122,7 @@ class StringConcatTest extends DottyBytecodeTest { chsq: java.lang.CharSequence, chrs: Array[Char]) = { val s1 = str + obj + v + z + c + b + s + i + f + l + d + sbuf + chsq + chrs - val s2 = String.valueOf(obj).nn + str + v + z + c + b + s + i + f + l + d + sbuf + chsq + chrs + val s2 = String.valueOf(obj) + str + v + z + c + b + s + i + f + l + d + sbuf + chsq + chrs s1 + "//" + s2 } def sbuf = { val r = new java.lang.StringBuffer(); r.append("sbuf"); r } diff --git a/compiler/test/dotty/tools/dotc/SettingsTests.scala b/compiler/test/dotty/tools/dotc/SettingsTests.scala index 996ab22f67b1..ec342db875a6 100644 --- a/compiler/test/dotty/tools/dotc/SettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala @@ -1,8 +1,6 @@ package dotty.tools package dotc -import scala.language.unsafeNulls - import reporting.StoreReporter import vulpix.TestConfiguration @@ -205,7 +203,7 @@ class SettingsTests { } @Test def `Output setting is overriding existing jar`: Unit = - val result = Using.resource(Files.createTempFile("myfile", ".jar").nn){ file => + val result = Using.resource(Files.createTempFile("myfile", ".jar")){ file => object Settings extends SettingGroup: val defaultDir = new PlainDirectory(Directory(".")) val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir) @@ -224,7 +222,7 @@ class SettingsTests { @Test def `Output setting is respecting previous setting`: Unit = val result = Using.resources( - Files.createTempFile("myfile", ".jar").nn, Files.createTempFile("myfile2", ".jar").nn + Files.createTempFile("myfile", ".jar"), Files.createTempFile("myfile2", ".jar") ){ (file1, file2) => object Settings extends SettingGroup: val defaultDir = new PlainDirectory(Directory(".")) @@ -250,7 +248,7 @@ class SettingsTests { }(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").nn){ file => + val result = Using.resource(Files.createTempFile("myfile", ".jar")){ file => object Settings extends SettingGroup: val defaultDir = new PlainDirectory(Directory(".")) val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true, deprecation = Deprecation.renamed("XtestOutput")) diff --git a/compiler/test/dotty/tools/dotc/TupleShowTests.scala b/compiler/test/dotty/tools/dotc/TupleShowTests.scala index 2d76c480b001..88e0587d7d71 100644 --- a/compiler/test/dotty/tools/dotc/TupleShowTests.scala +++ b/compiler/test/dotty/tools/dotc/TupleShowTests.scala @@ -71,7 +71,7 @@ class TupleShowTests extends DottyTest: /** On Windows the string literal in this test source file will be read with `\n` (b/c of "-encoding UTF8") * but the compiler will correctly emit \r\n as the line separator. * So we align the expected result to faithfully compare test results. */ - extension (str: String) def normEOL = if EOL == "\n" then str else str.replace("\n", EOL).nn + extension (str: String) def normEOL = if EOL == "\n" then str else str.replace("\n", EOL) def diff(exp: String, obt: String) = val min = math.min(exp.length, obt.length) diff --git a/compiler/test/dotty/tools/dotc/core/tasty/TastyHeaderUnpicklerTest.scala b/compiler/test/dotty/tools/dotc/core/tasty/TastyHeaderUnpicklerTest.scala index bde4246ef0f0..ddc88803854f 100644 --- a/compiler/test/dotty/tools/dotc/core/tasty/TastyHeaderUnpicklerTest.scala +++ b/compiler/test/dotty/tools/dotc/core/tasty/TastyHeaderUnpicklerTest.scala @@ -265,7 +265,7 @@ class TastyHeaderUnpicklerTest { object TastyHeaderUnpicklerTest { def fillHeader(maj: Int, min: Int, exp: Int, compiler: String): TastyBuffer = { - val compilerBytes = compiler.getBytes(java.nio.charset.StandardCharsets.UTF_8).nn + val compilerBytes = compiler.getBytes(java.nio.charset.StandardCharsets.UTF_8) val buf = new TastyBuffer(header.length + 32 + compilerBytes.length) for (ch <- header) buf.writeByte(ch.toByte) buf.writeNat(maj) @@ -304,7 +304,7 @@ object TastyHeaderUnpicklerTest { fail() } catch { - case err: UnpickleException => assert(err.getMessage.nn.contains(message)) + case err: UnpickleException => assert(err.getMessage.contains(message)) } } From dbd1db4a867af683a6a78fab8c50aef7837f5269 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Wed, 13 Nov 2024 15:43:06 +0100 Subject: [PATCH 4/4] Migrate some code related to file --- compiler/src/dotty/tools/MainGenericRunner.scala | 2 -- compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala | 2 +- .../src/dotty/tools/dotc/classpath/AggregateClassPath.scala | 2 -- .../src/dotty/tools/dotc/classpath/ClassPathFactory.scala | 4 ++-- .../src/dotty/tools/dotc/classpath/DirectoryClassPath.scala | 6 ++---- compiler/src/dotty/tools/dotc/classpath/FileUtils.scala | 2 -- .../tools/dotc/classpath/VirtualDirectoryClassPath.scala | 4 ++-- compiler/src/dotty/tools/dotc/coverage/Location.scala | 2 +- compiler/src/dotty/tools/dotc/transform/Pickler.scala | 2 +- compiler/src/dotty/tools/io/AbstractFile.scala | 6 +++--- 10 files changed, 12 insertions(+), 20 deletions(-) diff --git a/compiler/src/dotty/tools/MainGenericRunner.scala b/compiler/src/dotty/tools/MainGenericRunner.scala index bf477f019cba..ef3893b8b846 100644 --- a/compiler/src/dotty/tools/MainGenericRunner.scala +++ b/compiler/src/dotty/tools/MainGenericRunner.scala @@ -1,7 +1,5 @@ package dotty.tools -import scala.language.unsafeNulls - import scala.annotation.tailrec import scala.io.Source import scala.util.Try diff --git a/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala b/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala index e2ce73f79028..8a659c5dbfea 100644 --- a/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala +++ b/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala @@ -135,7 +135,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) { new JarEntryWriter(jarFile, jarManifestMainClass, jarCompressionLevel) } else if (file.isVirtual) new VirtualFileWriter(file) - else if (file.isDirectory) new DirEntryWriter(file.file.toPath) + else if (file.isDirectory) new DirEntryWriter(file.file.nn.toPath) else throw new IllegalStateException(s"don't know how to handle an output of $file [${file.getClass}]") } diff --git a/compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala index cd44ba27df96..472ff11f21c0 100644 --- a/compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala @@ -4,8 +4,6 @@ package dotty.tools package dotc.classpath -import scala.language.unsafeNulls - import java.net.URL import scala.collection.mutable.ArrayBuffer import scala.collection.immutable.ArraySeq diff --git a/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala b/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala index 416bcc85a783..f434b365c3c9 100644 --- a/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala +++ b/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala @@ -82,7 +82,7 @@ class ClassPathFactory { if (file.isJarOrZip) ZipAndJarSourcePathFactory.create(file) else if (file.isDirectory) - new DirectorySourcePath(file.file) + new DirectorySourcePath(file.file.nn) else sys.error(s"Unsupported sourcepath element: $file") } @@ -94,7 +94,7 @@ object ClassPathFactory { if (file.isJarOrZip) ZipAndJarClassPathFactory.create(file) else if (file.isDirectory) - new DirectoryClassPath(file.file) + new DirectoryClassPath(file.file.nn) else sys.error(s"Unsupported classpath element: $file") } diff --git a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala index aed5be45cb0d..4d9ab53d5fe3 100644 --- a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala @@ -3,8 +3,6 @@ */ package dotty.tools.dotc.classpath -import scala.language.unsafeNulls - import java.io.{File => JFile} import java.net.{URI, URL} import java.nio.file.{FileSystems, Files} @@ -119,7 +117,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo protected def toAbstractFile(f: JFile): AbstractFile = f.toPath.toPlainFile protected def isPackage(f: JFile): Boolean = f.isPackage - assert(dir != null, "Directory file in DirectoryFileLookup cannot be null") + assert(dir.asInstanceOf[JFile | Null] != null, "Directory file in DirectoryFileLookup cannot be null") def asURLs: Seq[URL] = Seq(dir.toURI.toURL) def asClassPathStrings: Seq[String] = Seq(dir.getPath) @@ -216,7 +214,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends ClassPath with NoSourcePaths { import java.nio.file.Path, java.nio.file.* - private val fileSystem: FileSystem = FileSystems.newFileSystem(ctSym, null: ClassLoader) + private val fileSystem: FileSystem = FileSystems.newFileSystem(ctSym, null.asInstanceOf[ClassLoader]) private val root: Path = fileSystem.getRootDirectories.iterator.next private val roots = Files.newDirectoryStream(root).iterator.asScala.toList diff --git a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala index 4fe57a722780..e51ba29483cb 100644 --- a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala +++ b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala @@ -4,8 +4,6 @@ package dotty.tools package dotc.classpath -import scala.language.unsafeNulls - import java.io.{File => JFile, FileFilter} import java.net.URL import dotty.tools.io.AbstractFile diff --git a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala index 0616d6c14ba6..bad52c0f4f58 100644 --- a/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala @@ -11,8 +11,8 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi type F = AbstractFile // From AbstractFileClassLoader - private final def lookupPath(base: AbstractFile)(pathParts: Seq[String], directory: Boolean): AbstractFile = { - var file: AbstractFile = base + private final def lookupPath(base: AbstractFile)(pathParts: Seq[String], directory: Boolean): AbstractFile | Null = { + var file: AbstractFile | Null = base val dirParts = pathParts.init.iterator while (dirParts.hasNext) { val dirPart = dirParts.next diff --git a/compiler/src/dotty/tools/dotc/coverage/Location.scala b/compiler/src/dotty/tools/dotc/coverage/Location.scala index de1a3db710a3..de8eb7a607db 100644 --- a/compiler/src/dotty/tools/dotc/coverage/Location.scala +++ b/compiler/src/dotty/tools/dotc/coverage/Location.scala @@ -46,5 +46,5 @@ object Location: s"$packageName.$className", classType, methodName, - source.file.absolute.jpath + source.file.absolute.jpath.nn ) diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index 108277599010..d2be45e80c00 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -413,7 +413,7 @@ class Pickler extends Phase { ) if ctx.isBestEffort then val outpath = - ctx.settings.outputDir.value.jpath.toAbsolutePath.normalize + ctx.settings.outputDir.value.jpath.nn.toAbsolutePath.normalize .resolve("META-INF") .resolve("best-effort") Files.createDirectories(outpath) diff --git a/compiler/src/dotty/tools/io/AbstractFile.scala b/compiler/src/dotty/tools/io/AbstractFile.scala index ee72297c2a4f..c9d28f98f103 100644 --- a/compiler/src/dotty/tools/io/AbstractFile.scala +++ b/compiler/src/dotty/tools/io/AbstractFile.scala @@ -115,7 +115,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] { def container : AbstractFile /** Returns the underlying File if any and null otherwise. */ - def file: JFile = try { + def file: JFile | Null = try { if (jpath == null) null else jpath.toFile } catch { @@ -123,7 +123,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] { } /** Returns the underlying Path if any and null otherwise. */ - def jpath: JPath + def jpath: JPath | Null /** An underlying source, if known. Mostly, a zip/jar file. */ def underlyingSource: Option[AbstractFile] = None @@ -201,7 +201,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] { /** Drill down through subdirs looking for the target, as in lookupName. * Ths target name is the last of parts. */ - final def lookupPath(parts: Seq[String], directory: Boolean): AbstractFile = + final def lookupPath(parts: Seq[String], directory: Boolean): AbstractFile | Null = var file: AbstractFile = this var i = 0 val n = parts.length - 1