Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0be2091

Browse files
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.*

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /