Skip to content

Commit 9fdf142

Browse files
s2sivathSuperCl4sh
s2sivath
authored andcommitted
Remove unsafe nulls
Remove some unsafe nulls Remove unsafe nulls
1 parent a553986 commit 9fdf142

16 files changed

+39
-39
lines changed

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

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

5-
import scala.language.unsafeNulls
5+
//import scala.language.unsafeNulls
66

77
import dotty.tools.dotc.core.Flags.*
88
import dotty.tools.dotc.core.Symbols.*
@@ -79,7 +79,7 @@ final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
7979
enclosingClass(classSym.originalOwner.originalLexicallyEnclosingClass)
8080
}
8181

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

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

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

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

11-
import scala.language.unsafeNulls
11+
//import scala.language.unsafeNulls
1212

1313
/**
1414
* 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.backend.jvm
22

3-
import scala.language.unsafeNulls
3+
//import scala.language.unsafeNulls
44

55
import dotty.tools.dotc.CompilationUnit
66
import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef}
@@ -68,10 +68,10 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
6868
null
6969

7070
if sym.isClass then
71-
val tastyAttrNode = if (mirrorClassNode ne null) mirrorClassNode else mainClassNode
71+
val tastyAttrNode = if (mirrorClassNode ne null) mirrorClassNode else mainClassNode // LHOTAK
7272
genTastyAndSetAttributes(sym, tastyAttrNode)
7373

74-
def registerGeneratedClass(classNode: ClassNode, isArtifact: Boolean): Unit =
74+
def registerGeneratedClass(classNode: ClassNode | Null, isArtifact: Boolean): Unit =
7575
if classNode ne null then
7676
generatedClasses += GeneratedClass(classNode,
7777
sourceClassName = sym.javaClassName,
@@ -131,7 +131,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
131131
}
132132
clsFile => {
133133
val className = cls.name.replace('/', '.')
134-
if (ctx.compilerCallback != null)
134+
if (ctx.compilerCallback ne null)
135135
ctx.compilerCallback.onClassGenerated(sourceFile, convertAbstractFile(clsFile), className)
136136

137137
ctx.withIncCallback: cb =>

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

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

3-
import scala.language.unsafeNulls
3+
//import scala.language.unsafeNulls
44

55
import dotty.tools.dotc.ast.tpd
66
import dotty.tools.dotc.core.Flags.*
@@ -44,14 +44,14 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSym
4444

4545
object DesugaredSelect extends DeconstructorCommon[tpd.Tree] {
4646

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

4949
override def isEmpty: Boolean =
5050
desugared eq null
5151

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

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

5656
override def unapply(s: tpd.Tree): this.type = {
5757
s match {
@@ -69,17 +69,17 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSym
6969
}
7070

7171
object ArrayValue extends DeconstructorCommon[tpd.JavaSeqLiteral] {
72-
def _1: Type = field.tpe match {
72+
def _1: Type = field.nn.tpe match {
7373
case JavaArrayType(elem) => elem
7474
case _ =>
75-
report.error(em"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
75+
report.error(em"JavaSeqArray with type ${field.nn.tpe} reached backend: $field", ctx.source.atSpan(field.nn.span))
7676
UnspecifiedErrorType
7777
}
78-
def _2: List[Tree] = field.elems
78+
def _2: List[Tree] = field.nn.elems
7979
}
8080

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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
17+
//import scala.language.unsafeNulls
1818
import scala.compiletime.uninitialized
1919

2020
/**

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

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

6-
import scala.language.unsafeNulls
6+
//import scala.language.unsafeNulls
77

88
import java.io.File
99
import java.net.URL
@@ -21,7 +21,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends Efficie
2121
val zipFile: File
2222
def release: Option[String]
2323

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

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

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

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

5-
import scala.language.unsafeNulls
5+
//import scala.language.unsafeNulls
66

77
import io.*
88

@@ -30,10 +30,10 @@ class OutputDirs {
3030

3131
/** Check that dir is exists and is a directory. */
3232
private def checkDir(dir: AbstractFile, name: String, allowJar: Boolean = false): AbstractFile = (
33-
if (dir != null && dir.isDirectory)
33+
if ((dir ne null) && dir.isDirectory)
3434
dir
3535
// was: else if (allowJar && dir == null && Path.isJarOrZip(name, false))
36-
else if (allowJar && dir == null && Jar.isJarOrZip(File(name), false))
36+
else if (allowJar && (dir eq null) && Jar.isJarOrZip(File(name), false))
3737
new PlainFile(Path(name))
3838
else
3939
throw new FatalError(name + " does not exist or is not a directory"))

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

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

4-
import scala.language.unsafeNulls
4+
//import scala.language.unsafeNulls
55

66
import core.*
77
import Contexts.*

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

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

4-
import scala.language.unsafeNulls
4+
//import scala.language.unsafeNulls
55

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

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

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

3-
import scala.language.unsafeNulls
3+
import scala.language.unsafeNulls //
44

55
/** A specialized implementation of GenericHashMap with standard hashCode and equals
66
* as comparison

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

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

3-
import scala.language.unsafeNulls
3+
//import scala.language.unsafeNulls
44

55
import reflect.ClassTag
66
import annotation.tailrec
@@ -17,7 +17,7 @@ import annotation.tailrec
1717
* get promoted to be first in the queue. Elements are evicted
1818
* at the `last` position.
1919
*/
20-
class LRUCache[Key >: Null <: AnyRef : ClassTag, Value >: Null: ClassTag] {
20+
class LRUCache[Key >: Null <: AnyRef | Null : ClassTag, Value >: Null: ClassTag] {
2121
import LRUCache.*
2222
val keys: Array[Key] = new Array[Key](Retained)
2323
val values: Array[Value] = new Array(Retained)

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

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

5-
import scala.language.unsafeNulls
5+
//import scala.language.unsafeNulls
66

77
import core.Names.*
88

@@ -55,7 +55,7 @@ object NameTransformer {
5555
* the Scala spec as well as the Java spec.
5656
*/
5757
def encode(name: SimpleName): SimpleName = {
58-
var buf: StringBuilder = null
58+
var buf: StringBuilder | Null = null
5959
val len = name.length
6060
var i = 0
6161
while (i < len) {
@@ -88,11 +88,11 @@ object NameTransformer {
8888
*/
8989
def decode(name: SimpleName): SimpleName = {
9090
//System.out.println("decode: " + name);//DEBUG
91-
var buf: StringBuilder = null
91+
var buf: StringBuilder | Null = null
9292
val len = name.length
9393
var i = 0
9494
while (i < len) {
95-
var ops: OpCodes = null
95+
var ops: OpCodes | Null = null
9696
var unicode = false
9797
val c = name(i)
9898
if (c == '$' && i + 2 < len) {

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

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

3-
import scala.language.unsafeNulls
3+
import scala.language.unsafeNulls //
44

55
import collection.mutable
66

@@ -219,7 +219,7 @@ object SimpleIdentitySet {
219219
override def ++ [E >: Elem <: AnyRef](that: SimpleIdentitySet[E]): SimpleIdentitySet[E] =
220220
that match {
221221
case that: SetN[?] =>
222-
var toAdd: mutable.ArrayBuffer[AnyRef] = null
222+
var toAdd: mutable.ArrayBuffer[AnyRef] | Null = null
223223
var i = 0
224224
val limit = that.xs.length
225225
while (i < limit) {
@@ -249,7 +249,7 @@ object SimpleIdentitySet {
249249
case that: SetN[?] =>
250250
// both sets are large, optimize assuming they are similar
251251
// by starting from empty set and adding elements
252-
var toAdd: mutable.ArrayBuffer[AnyRef] = null
252+
var toAdd: mutable.ArrayBuffer[AnyRef] | Null = null
253253
val thisSize = this.size
254254
val thatSize = that.size
255255
val thatElems = that.xs

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

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

5-
import scala.language.unsafeNulls
5+
//import scala.language.unsafeNulls
66

77
import printing.{Showable, Printer}
88
import printing.Texts.*
@@ -67,7 +67,7 @@ extends SrcPos, interfaces.SourcePosition, Showable {
6767
def toSynthetic: SourcePosition = withSpan(span.toSynthetic)
6868

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

7272
/** Inner most position that is contained within the `outermost` position.
7373
* Most precise position that comes from the call site.
@@ -86,7 +86,7 @@ extends SrcPos, interfaces.SourcePosition, Showable {
8686
}
8787

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

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

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

66
package dotty.tools.io
77

8-
import scala.language.unsafeNulls
8+
//import scala.language.unsafeNulls
99

1010
import java.net.URL
1111
import java.io.{ BufferedInputStream, InputStream }

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ object Build {
535535
"scala2-library-tasty"
536536
)
537537

538-
val enableBspAllProjects = false
538+
val enableBspAllProjects = true
539539

540540
// Settings used when compiling dotty with a non-bootstrapped dotty
541541
lazy val commonBootstrappedSettings = commonDottySettings ++ Seq(

0 commit comments

Comments
 (0)