Skip to content

Commit 89e617d

Browse files
authored
Explicitly null check the stdlib (#23566)
The PR enables explicit nulls for stdlib. The detailed review guide is at: #23566 (comment)
2 parents e3b4bed + e6bd8f4 commit 89e617d

File tree

145 files changed

+1490
-1387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1490
-1387
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ object MainGenericCompiler {
131131
val tStopAtLvl="-XX:TieredStopAtLevel=1"
132132
println(s"ignoring deprecated -Oshort flag, please add `-J$addTC` and `-J$tStopAtLvl` flags manually")
133133
process(tail, settings)
134-
case javaOption(stripped) :: tail =>
134+
case javaOption(stripped: String) :: tail =>
135135
process(tail, settings.withJavaArgs(stripped))
136-
case javaPropOption(opt, value) :: tail =>
136+
case javaPropOption(opt: String, value: String) :: tail =>
137137
process(tail, settings.withJavaProps(opt -> value))
138138
case arg :: tail =>
139139
process(tail, settings.withResidualArgs(arg))

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ object MainGenericRunner {
143143
processArgs(tail, settings.noSave)
144144
case "-with-compiler" :: tail =>
145145
processArgs(tail, settings.withCompiler)
146-
case (o @ javaOption(striped)) :: tail =>
146+
case (o @ javaOption(striped: String)) :: tail =>
147147
processArgs(tail, settings.withJavaArgs(striped).withScalaArgs(o))
148148
case (o @ scalaOption(_*)) :: tail =>
149149
val remainingArgs = CommandLineParser.expandArg(o) ++ tail

compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ final class JSDefinitions()(using Context) {
289289
@threadUnsafe lazy val EnumerationClass = requiredClass("scala.Enumeration")
290290
@threadUnsafe lazy val Enumeration_Value_NoArg = EnumerationClass.requiredValue(nmeValue)
291291
@threadUnsafe lazy val Enumeration_Value_IntArg = EnumerationClass.requiredMethod(nmeValue, List(defn.IntType))
292-
@threadUnsafe lazy val Enumeration_Value_StringArg = EnumerationClass.requiredMethod(nmeValue, List(defn.StringType))
293-
@threadUnsafe lazy val Enumeration_Value_IntStringArg = EnumerationClass.requiredMethod(nmeValue, List(defn.IntType, defn.StringType))
292+
@threadUnsafe lazy val Enumeration_Value_StringArg = EnumerationClass.requiredMethod(nmeValue, List(OrNull(defn.StringType)))
293+
@threadUnsafe lazy val Enumeration_Value_IntStringArg = EnumerationClass.requiredMethod(nmeValue, List(defn.IntType, OrNull(defn.StringType)))
294294
@threadUnsafe lazy val Enumeration_nextName = EnumerationClass.requiredMethod(termName("nextName"))
295295

296296
@threadUnsafe lazy val EnumerationValClass = EnumerationClass.requiredClass("Val")
297297
@threadUnsafe lazy val Enumeration_Val_NoArg = EnumerationValClass.requiredMethod(nme.CONSTRUCTOR, Nil)
298298
@threadUnsafe lazy val Enumeration_Val_IntArg = EnumerationValClass.requiredMethod(nme.CONSTRUCTOR, List(defn.IntType))
299-
@threadUnsafe lazy val Enumeration_Val_StringArg = EnumerationValClass.requiredMethod(nme.CONSTRUCTOR, List(defn.StringType))
300-
@threadUnsafe lazy val Enumeration_Val_IntStringArg = EnumerationValClass.requiredMethod(nme.CONSTRUCTOR, List(defn.IntType, defn.StringType))
299+
@threadUnsafe lazy val Enumeration_Val_StringArg = EnumerationValClass.requiredMethod(nme.CONSTRUCTOR, List(OrNull(defn.StringType)))
300+
@threadUnsafe lazy val Enumeration_Val_IntStringArg = EnumerationValClass.requiredMethod(nme.CONSTRUCTOR, List(defn.IntType, OrNull(defn.StringType)))
301301

302302
def isValueMethod(sym: Symbol)(using Context): Boolean =
303303
sym.name == nmeValue && sym.owner == EnumerationClass

compiler/src/dotty/tools/dotc/core/Comments.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ object Comments {
404404
val raw = ctx.docCtx.flatMap(_.docstring(sym).map(_.raw)).getOrElse("")
405405
defs(sym) ++= defines(raw).map { str =>
406406
val start = skipWhitespace(str, "@define".length)
407-
val (key, Trim(value)) = str.splitAt(skipVariable(str, start)): @unchecked
407+
val (key, Trim(value: String)) = str.splitAt(skipVariable(str, start)): @unchecked
408408
variableName(key.drop(start)) -> value.replaceAll("\\s+\\*+$", "")
409409
}
410410
}

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,7 @@ class MissingImplicitArgument(
30003000
val idx = paramNames.indexOf(name)
30013001
if (idx >= 0) Some(i"${args(idx)}") else None
30023002
"""\$\{\s*([^}\s]+)\s*\}""".r.replaceAllIn(raw, (_: Regex.Match) match
3003-
case Regex.Groups(v) => quoteReplacement(translate(v).getOrElse("?" + v)).nn
3003+
case Regex.Groups(v: String) => quoteReplacement(translate(v).getOrElse("?" + v)).nn
30043004
)
30053005

30063006
/** @param rawMsg Message template with variables, e.g. "Variable A is ${A}"

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ object Scala3:
382382
object LocalSymbol:
383383

384384
def unapply(symbolInfo: SymbolInformation): Option[Int] = symbolInfo.symbol match
385-
case locals(ints) =>
385+
case locals(ints: String) =>
386386
val bi = BigInt(ints)
387387
if bi.isValidInt then
388388
Some(bi.toInt)

compiler/src/dotty/tools/repl/ParseResult.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ object ParseResult {
180180
val sourceCode = source.content().mkString
181181
sourceCode match {
182182
case "" => Newline
183-
case CommandExtract(cmd, arg) => {
183+
case CommandExtract(cmd: String, arg: String) => {
184184
val matchingCommands = commands.filter((command, _) => command.startsWith(cmd))
185185
matchingCommands match {
186186
case Nil => UnknownCommand(cmd)

compiler/src/dotty/tools/scripting/Main.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object Main:
7878
writer.close()
7979
end writeJarfile
8080

81-
def pathsep = sys.props("path.separator")
81+
def pathsep: String = sys.props("path.separator").nn
8282

8383
extension(path: String) {
8484
// Normalize path separator, convert relative path to absolute
@@ -102,4 +102,4 @@ object Main:
102102
def secondChar: String = path.take(2).drop(1).mkString("")
103103
}
104104

105-
lazy val userDir = sys.props("user.dir").norm
105+
lazy val userDir: String = sys.props("user.dir").nn.norm

compiler/src/dotty/tools/scripting/Util.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object Util:
5656
end match
5757
end detectMainClassAndMethod
5858

59-
def pathsep = sys.props("path.separator")
59+
def pathsep: String = sys.props("path.separator").nn
6060

6161
end Util
6262

compiler/test/dotty/tools/debug/DebugStepAssert.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ private[debug] object DebugStepAssert:
4949
given location: CheckFileLocation = CheckFileLocation(checkFile, allLines.size - lines.size + 1)
5050
lines match
5151
case Nil => acc.reverse
52-
case break(className , lineStr) :: tail =>
52+
case break(className: String, lineStr: String) :: tail =>
5353
val breakpointLine = lineStr.toInt
5454
val step = DebugStepAssert(Break(className, breakpointLine), checkClassAndLine(className, breakpointLine))
5555
loop(tail, step :: acc)
56-
case step(pattern) :: tail =>
56+
case step(pattern: String) :: tail =>
5757
val step = DebugStepAssert(Step, checkLineOrMethod(pattern))
5858
loop(tail, step :: acc)
59-
case next(pattern) :: tail =>
59+
case next(pattern: String) :: tail =>
6060
val step = DebugStepAssert(Next, checkLineOrMethod(pattern))
6161
loop(tail, step :: acc)
62-
case eval(expr) :: tail0 =>
62+
case eval(expr: String) :: tail0 =>
6363
val (assertion, tail1) = parseEvalAssertion(tail0)
6464
val step = DebugStepAssert(Eval(expr), assertion)
6565
loop(tail1, step :: acc)
@@ -78,8 +78,8 @@ private[debug] object DebugStepAssert:
7878
lines match
7979
case Nil => throw new Exception(s"Missing result or error")
8080
case trailing() :: tail => parseEvalAssertion(tail)
81-
case result(expected) :: tail => (checkResult(expected), tail)
82-
case error(expected) :: tail => (checkError(Seq(expected)), tail)
81+
case result(expected: String) :: tail => (checkResult(expected), tail)
82+
case error(expected: String) :: tail => (checkError(Seq(expected)), tail)
8383
case multiLineError() :: tail0 =>
8484
val (expected, tail1) = tail0.span(_.startsWith(" "))
8585
(checkError(expected.map(_.stripPrefix(" "))), tail1)

0 commit comments

Comments
 (0)