Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0be2091

Browse files
authored
Remove some unsafe nulls (#23309)
Remove some more unsafe nulls.
2 parents 1e807fc + 33da1ee commit 0be2091

17 files changed

+25
-43
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package dotty.tools
22
package backend
33
package jvm
44

5-
import scala.language.unsafeNulls
6-
75
import dotty.tools.dotc.core.Flags.*
86
import dotty.tools.dotc.core.Symbols.*
97
import dotty.tools.dotc.report
@@ -79,7 +77,7 @@ final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
7977
enclosingClass(classSym.originalOwner.originalLexicallyEnclosingClass)
8078
}
8179

82-
/*final*/ case class EnclosingMethodEntry(owner: String, name: String, methodDescriptor: String)
80+
/*final*/ case class EnclosingMethodEntry(owner: String, name: String | Null, methodDescriptor: String | Null)
8381

8482
/**
8583
* Data for emitting an EnclosingMethod attribute. None if `classSym` is a member class (not

compiler/src/dotty/tools/backend/jvm/BackendUtils.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import scala.collection.mutable
88
import scala.jdk.CollectionConverters.*
99
import dotty.tools.dotc.report
1010

11-
import scala.language.unsafeNulls
1211

1312
/**
1413
* This component hosts tools and utilities used in the backend that require access to a `BTypes`

compiler/src/dotty/tools/backend/jvm/CodeGen.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dotty.tools.backend.jvm
22

3-
import scala.language.unsafeNulls
43

54
import dotty.tools.dotc.CompilationUnit
65
import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef}
@@ -71,7 +70,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
7170
val tastyAttrNode = if (mirrorClassNode ne null) mirrorClassNode else mainClassNode
7271
genTastyAndSetAttributes(sym, tastyAttrNode)
7372

74-
def registerGeneratedClass(classNode: ClassNode, isArtifact: Boolean): Unit =
73+
def registerGeneratedClass(classNode: ClassNode | Null, isArtifact: Boolean): Unit =
7574
if classNode ne null then
7675
generatedClasses += GeneratedClass(classNode,
7776
sourceClassName = sym.javaClassName,
@@ -131,7 +130,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
131130
}
132131
clsFile => {
133132
val className = cls.name.replace('/', '.')
134-
if (ctx.compilerCallback != null)
133+
if (ctx.compilerCallback ne null)
135134
ctx.compilerCallback.onClassGenerated(sourceFile, convertAbstractFile(clsFile), className)
136135

137136
ctx.withIncCallback: cb =>

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dotty.tools.backend.jvm
22

3-
import scala.language.unsafeNulls
43

54
import dotty.tools.dotc.ast.tpd
65
import dotty.tools.dotc.core.Flags.*
@@ -44,14 +43,14 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSym
4443

4544
object DesugaredSelect extends DeconstructorCommon[tpd.Tree] {
4645

47-
var desugared: tpd.Select = null
46+
var desugared: tpd.Select | Null = null
4847

4948
override def isEmpty: Boolean =
5049
desugared eq null
5150

52-
def _1: Tree = desugared.qualifier
51+
def _1: Tree = desugared.nn.qualifier
5352

54-
def _2: Name = desugared.name
53+
def _2: Name = desugared.nn.name
5554

5655
override def unapply(s: tpd.Tree): this.type = {
5756
s match {
@@ -69,17 +68,17 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSym
6968
}
7069

7170
object ArrayValue extends DeconstructorCommon[tpd.JavaSeqLiteral] {
72-
def _1: Type = field.tpe match {
71+
def _1: Type = field.nn.tpe match {
7372
case JavaArrayType(elem) => elem
7473
case _ =>
75-
report.error(em"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
74+
report.error(em"JavaSeqArray with type ${field.nn.tpe} reached backend: $field", ctx.source.atSpan(field.nn.span))
7675
UnspecifiedErrorType
7776
}
78-
def _2: List[Tree] = field.elems
77+
def _2: List[Tree] = field.nn.elems
7978
}
8079

81-
abstract class DeconstructorCommon[T >: Null <: AnyRef] {
82-
var field: T = null
80+
abstract class DeconstructorCommon[T <: AnyRef] {
81+
var field: T | Null = null
8382
def get: this.type = this
8483
def isEmpty: Boolean = field eq null
8584
def isDefined = !isEmpty

compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import scala.util.control.NonFatal
1414
import dotty.tools.dotc.core.Phases
1515
import dotty.tools.dotc.core.Decorators.em
1616

17-
import scala.language.unsafeNulls
1817
import scala.compiletime.uninitialized
1918

2019
/**
@@ -189,4 +188,4 @@ final private class CompilationUnitInPostProcess(private var classes: List[Gener
189188
var task: Future[Unit] = uninitialized
190189

191190
val bufferedReporting = new PostProcessorFrontendAccess.BufferingBackendReporting()
192-
}
191+
}

compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
package dotty.tools.dotc.classpath
55

6-
import scala.language.unsafeNulls
76

87
import java.io.File
98
import java.net.URL
@@ -21,7 +20,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends Efficie
2120
val zipFile: File
2221
def release: Option[String]
2322

24-
assert(zipFile != null, "Zip file in ZipArchiveFileLookup cannot be null")
23+
assert(zipFile ne null, "Zip file in ZipArchiveFileLookup cannot be null")
2524

2625
override def asURLs: Seq[URL] = Seq(zipFile.toURI.toURL)
2726
override def asClassPathStrings: Seq[String] = Seq(zipFile.getPath)

compiler/src/dotty/tools/dotc/config/OutputDirs.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools
22
package dotc
33
package config
44

5-
import scala.language.unsafeNulls
65

76
import io.*
87

@@ -30,10 +29,10 @@ class OutputDirs {
3029

3130
/** Check that dir is exists and is a directory. */
3231
private def checkDir(dir: AbstractFile, name: String, allowJar: Boolean = false): AbstractFile = (
33-
if (dir != null && dir.isDirectory)
32+
if ((dir ne null) && dir.isDirectory)
3433
dir
3534
// was: else if (allowJar && dir == null && Path.isJarOrZip(name, false))
36-
else if (allowJar && dir == null && Jar.isJarOrZip(File(name), false))
35+
else if (allowJar && (dir eq null) && Jar.isJarOrZip(File(name), false))
3736
new PlainFile(Path(name))
3837
else
3938
throw new FatalError(name + " does not exist or is not a directory"))

compiler/src/dotty/tools/dotc/config/Properties.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools
22
package dotc
33
package config
44

5-
import scala.language.unsafeNulls
65

76
import scala.annotation.internal.sharable
87

@@ -45,7 +44,7 @@ trait PropertiesTrait {
4544

4645
def propIsSet(name: String): Boolean = System.getProperty(name) != null
4746
def propIsSetTo(name: String, value: String): Boolean = propOrNull(name) == value
48-
def propOrElse(name: String, alt: => String): String = Option(System.getProperty(name)).getOrElse(alt)
47+
def propOrElse(name: String, alt: => String | Null): String = Option(System.getProperty(name)).getOrElse(alt)
4948
def propOrEmpty(name: String): String = propOrElse(name, "")
5049
def propOrNull(name: String): String = propOrElse(name, null)
5150
def propOrNone(name: String): Option[String] = Option(propOrNull(name))

compiler/src/dotty/tools/dotc/coverage/Serializer.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package coverage
33

44
import java.nio.file.{Path, Paths, Files}
55
import java.io.Writer
6-
import scala.language.unsafeNulls
76
import scala.collection.mutable.StringBuilder
87

98
/**

compiler/src/dotty/tools/dotc/sbt/APIUtils.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.dotc
22
package sbt
33

4-
import scala.language.unsafeNulls
54

65
import core.*
76
import Contexts.*

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.dotc
22
package transform
33

4-
import scala.language.unsafeNulls
54

65
import java.io.{PrintWriter, StringWriter}
76
import java.lang.reflect.{InvocationTargetException, Method => JLRMethod}

compiler/src/dotty/tools/dotc/util/LRUCache.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dotty.tools.dotc.util
22

3-
import scala.language.unsafeNulls
43

54
import reflect.ClassTag
65
import annotation.tailrec
@@ -17,7 +16,7 @@ import annotation.tailrec
1716
* get promoted to be first in the queue. Elements are evicted
1817
* at the `last` position.
1918
*/
20-
class LRUCache[Key >: Null <: AnyRef : ClassTag, Value >: Null: ClassTag] {
19+
class LRUCache[Key >: Null <: AnyRef | Null : ClassTag, Value >: Null: ClassTag] {
2120
import LRUCache.*
2221
val keys: Array[Key] = new Array[Key](Retained)
2322
val values: Array[Value] = new Array(Retained)

compiler/src/dotty/tools/dotc/util/NameTransformer.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools
22
package dotc
33
package util
44

5-
import scala.language.unsafeNulls
65

76
import core.Names.*
87

@@ -55,7 +54,7 @@ object NameTransformer {
5554
* the Scala spec as well as the Java spec.
5655
*/
5756
def encode(name: SimpleName): SimpleName = {
58-
var buf: StringBuilder = null
57+
var buf: StringBuilder | Null = null
5958
val len = name.length
6059
var i = 0
6160
while (i < len) {
@@ -88,11 +87,11 @@ object NameTransformer {
8887
*/
8988
def decode(name: SimpleName): SimpleName = {
9089
//System.out.println("decode: " + name);//DEBUG
91-
var buf: StringBuilder = null
90+
var buf: StringBuilder | Null = null
9291
val len = name.length
9392
var i = 0
9493
while (i < len) {
95-
var ops: OpCodes = null
94+
var ops: OpCodes | Null = null
9695
var unicode = false
9796
val c = name(i)
9897
if (c == '$' && i + 2 < len) {

compiler/src/dotty/tools/dotc/util/SimpleIdentitySet.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dotty.tools.dotc.util
22

3-
import scala.language.unsafeNulls
43

54
import collection.mutable
65

@@ -222,7 +221,7 @@ object SimpleIdentitySet {
222221
override def ++ [E >: Elem <: AnyRef](that: SimpleIdentitySet[E]): SimpleIdentitySet[E] =
223222
that match {
224223
case that: SetN[?] =>
225-
var toAdd: mutable.ArrayBuffer[AnyRef] = null
224+
var toAdd: mutable.ArrayBuffer[AnyRef] | Null = null
226225
var i = 0
227226
val limit = that.xs.length
228227
while (i < limit) {
@@ -252,7 +251,7 @@ object SimpleIdentitySet {
252251
case that: SetN[?] =>
253252
// both sets are large, optimize assuming they are similar
254253
// by starting from empty set and adding elements
255-
var toAdd: mutable.ArrayBuffer[AnyRef] = null
254+
var toAdd: mutable.ArrayBuffer[AnyRef] | Null = null
256255
val thisSize = this.size
257256
val thatSize = that.size
258257
val thatElems = that.xs

compiler/src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools
22
package dotc
33
package util
44

5-
import scala.language.unsafeNulls
65

76
import printing.{Showable, Printer}
87
import printing.Texts.*
@@ -67,7 +66,7 @@ extends SrcPos, interfaces.SourcePosition, Showable {
6766
def toSynthetic: SourcePosition = withSpan(span.toSynthetic)
6867

6968
def outermost: SourcePosition =
70-
if outer == null || outer == NoSourcePosition then this else outer.outermost
69+
if (outer eq null) || outer == NoSourcePosition then this else outer.outermost
7170

7271
/** Inner most position that is contained within the `outermost` position.
7372
* Most precise position that comes from the call site.
@@ -86,7 +85,7 @@ extends SrcPos, interfaces.SourcePosition, Showable {
8685
}
8786

8887
/** A sentinel for a non-existing source position */
89-
@sharable object NoSourcePosition extends SourcePosition(NoSource, NoSpan, null) {
88+
@sharable object NoSourcePosition extends SourcePosition(NoSource, NoSpan) {
9089
override def line: Int = -1
9190
override def column: Int = -1
9291
override def toString: String = "?"

compiler/src/dotty/tools/io/Streamable.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package dotty.tools.io
77

8-
import scala.language.unsafeNulls
98

109
import java.net.URL
1110
import java.io.{ BufferedInputStream, InputStream }

compiler/src/dotty/tools/runner/ScalaClassLoader.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools
22
package runner
33

4-
import scala.language.unsafeNulls
54

65
import java.lang.ClassLoader
76
import java.lang.invoke.{MethodHandles, MethodType}
@@ -64,7 +63,7 @@ object ScalaClassLoader {
6463
def fromURLsParallelCapable(urls: Seq[URL], parent: ClassLoader | Null = null): URLClassLoader =
6564
new URLClassLoader(urls.toArray, if parent == null then bootClassLoader else parent)
6665

67-
@sharable private val bootClassLoader: ClassLoader =
66+
@sharable private val bootClassLoader: ClassLoader | Null =
6867
if scala.util.Properties.isJavaAtLeast("9") then
6968
try
7069
ClassLoader.getSystemClassLoader.getParent

0 commit comments

Comments
 (0)