Skip to content

Commit e0e83d5

Browse files
committed
Add comments
1 parent 258d123 commit e0e83d5

File tree

6 files changed

+39
-84
lines changed

6 files changed

+39
-84
lines changed

library-js/src/scala/runtime/ScalaRunTime.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,17 @@ object ScalaRunTime {
252252
case s => s + "\n"
253253
}
254254

255-
// For backwards compatibility with code compiled without -Yexplicit-nulls
255+
// For backward compatibility with code compiled without -Yexplicit-nulls.
256+
// If `a` is null, return null; otherwise, return `f`.
257+
// Have to add a private mapNull here to avoid errors
256258
private inline def mapNull[A, B](a: A, inline f: B): B =
257259
if((a: A | Null) == null) null.asInstanceOf[B] else f
258260

261+
// For the following functions, both the parameter and the return type are non-nullable.
262+
// However, if a null reference is passed explicitly, this method will still return null.
263+
// We intentionally keep this signature to discourage passing nulls implicitly while
264+
// preserving the previous behavior for backward compatibility.
265+
259266
// Convert arrays to immutable.ArraySeq for use with Java varargs:
260267
def genericWrapArray[T](xs: Array[T]): ArraySeq[T] =
261268
mapNull(xs, ArraySeq.unsafeWrapArray(xs))

library/src/scala/IArray.scala

Lines changed: 17 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -336,25 +336,17 @@ object IArray:
336336
private inline def mapNull[A, B](a: A, inline f: B): B =
337337
if((a: A | Null) == null) null.asInstanceOf[B] else f
338338

339-
/** Conversion from IArray to immutable.ArraySeq.
340-
*
341-
* Note: Both the parameter and the return type are non-nullable. However, if a null
342-
* reference is passed explicitly, this method will still return null. We intentionally
343-
* keep this signature to discourage passing nulls implicitly while preserving the
344-
* previous behavior for backward compatibility.
345-
*/
339+
// For the following functions, both the parameter and the return type are non-nullable.
340+
// However, if a null reference is passed explicitly, this method will still return null.
341+
// We intentionally keep this signature to discourage passing nulls implicitly while
342+
// preserving the previous behavior for backward compatibility.
343+
344+
/** Conversion from IArray to immutable.ArraySeq */
346345
implicit def genericWrapArray[T](arr: IArray[T]): ArraySeq[T] =
347346
mapNull(arr, ArraySeq.unsafeWrapArray(arr))
348347

349-
/** Conversion from IArray to immutable.ArraySeq.
350-
*
351-
* Note: Both the parameter and the return type are non-nullable. However, if a null
352-
* reference is passed explicitly, this method will still return null. We intentionally
353-
* keep this signature to discourage passing nulls implicitly while preserving the
354-
* previous behavior for backward compatibility.
355-
*/
356-
// TODO!!! only for stdliib migration!
357-
import scala.language.unsafeNulls
348+
/** Conversion from IArray to immutable.ArraySeq */
349+
import scala.language.unsafeNulls // TODO!!! only for stdliib migration!
358350
implicit def wrapRefArray[T <: AnyRef | Null](arr: IArray[T]): ArraySeq.ofRef[T] =
359351
// Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef | Null]
360352
// is as good as another for all T <: AnyRef | Null. Instead of creating 100,000,000
@@ -365,93 +357,39 @@ object IArray:
365357
else ArraySeq.ofRef[AnyRef](arr.asInstanceOf[Array[AnyRef]]).asInstanceOf[ArraySeq.ofRef[T]]
366358
)
367359

368-
/** Conversion from IArray to immutable.ArraySeq.
369-
*
370-
* Note: Both the parameter and the return type are non-nullable. However, if a null
371-
* reference is passed explicitly, this method will still return null. We intentionally
372-
* keep this signature to discourage passing nulls implicitly while preserving the
373-
* previous behavior for backward compatibility.
374-
*/
360+
/** Conversion from IArray to immutable.ArraySeq */
375361
implicit def wrapIntArray(arr: IArray[Int]): ArraySeq.ofInt =
376362
mapNull(arr, new ArraySeq.ofInt(arr.asInstanceOf[Array[Int]]))
377363

378-
/** Conversion from IArray to immutable.ArraySeq.
379-
*
380-
* Note: Both the parameter and the return type are non-nullable. However, if a null
381-
* reference is passed explicitly, this method will still return null. We intentionally
382-
* keep this signature to discourage passing nulls implicitly while preserving the
383-
* previous behavior for backward compatibility.
384-
*/
364+
/** Conversion from IArray to immutable.ArraySeq */
385365
implicit def wrapDoubleIArray(arr: IArray[Double]): ArraySeq.ofDouble =
386366
mapNull(arr, new ArraySeq.ofDouble(arr.asInstanceOf[Array[Double]]))
387367

388-
/** Conversion from IArray to immutable.ArraySeq.
389-
*
390-
* Note: Both the parameter and the return type are non-nullable. However, if a null
391-
* reference is passed explicitly, this method will still return null. We intentionally
392-
* keep this signature to discourage passing nulls implicitly while preserving the
393-
* previous behavior for backward compatibility.
394-
*/
368+
/** Conversion from IArray to immutable.ArraySeq */
395369
implicit def wrapLongIArray(arr: IArray[Long]): ArraySeq.ofLong =
396370
mapNull(arr, new ArraySeq.ofLong(arr.asInstanceOf[Array[Long]]))
397371

398-
/** Conversion from IArray to immutable.ArraySeq.
399-
*
400-
* Note: Both the parameter and the return type are non-nullable. However, if a null
401-
* reference is passed explicitly, this method will still return null. We intentionally
402-
* keep this signature to discourage passing nulls implicitly while preserving the
403-
* previous behavior for backward compatibility.
404-
*/
372+
/** Conversion from IArray to immutable.ArraySeq */
405373
implicit def wrapFloatIArray(arr: IArray[Float]): ArraySeq.ofFloat =
406374
mapNull(arr, new ArraySeq.ofFloat(arr.asInstanceOf[Array[Float]]))
407375

408-
/** Conversion from IArray to immutable.ArraySeq.
409-
*
410-
* Note: Both the parameter and the return type are non-nullable. However, if a null
411-
* reference is passed explicitly, this method will still return null. We intentionally
412-
* keep this signature to discourage passing nulls implicitly while preserving the
413-
* previous behavior for backward compatibility.
414-
*/
376+
/** Conversion from IArray to immutable.ArraySeq */
415377
implicit def wrapCharIArray(arr: IArray[Char]): ArraySeq.ofChar =
416378
mapNull(arr, new ArraySeq.ofChar(arr.asInstanceOf[Array[Char]]))
417379

418-
/** Conversion from IArray to immutable.ArraySeq.
419-
*
420-
* Note: Both the parameter and the return type are non-nullable. However, if a null
421-
* reference is passed explicitly, this method will still return null. We intentionally
422-
* keep this signature to discourage passing nulls implicitly while preserving the
423-
* previous behavior for backward compatibility.
424-
*/
380+
/** Conversion from IArray to immutable.ArraySeq */
425381
implicit def wrapByteIArray(arr: IArray[Byte]): ArraySeq.ofByte =
426382
mapNull(arr, new ArraySeq.ofByte(arr.asInstanceOf[Array[Byte]]))
427383

428-
/** Conversion from IArray to immutable.ArraySeq.
429-
*
430-
* Note: Both the parameter and the return type are non-nullable. However, if a null
431-
* reference is passed explicitly, this method will still return null. We intentionally
432-
* keep this signature to discourage passing nulls implicitly while preserving the
433-
* previous behavior for backward compatibility.
434-
*/
384+
/** Conversion from IArray to immutable.ArraySeq */
435385
implicit def wrapShortIArray(arr: IArray[Short]): ArraySeq.ofShort =
436386
mapNull(arr, new ArraySeq.ofShort(arr.asInstanceOf[Array[Short]]))
437387

438-
/** Conversion from IArray to immutable.ArraySeq.
439-
*
440-
* Note: Both the parameter and the return type are non-nullable. However, if a null
441-
* reference is passed explicitly, this method will still return null. We intentionally
442-
* keep this signature to discourage passing nulls implicitly while preserving the
443-
* previous behavior for backward compatibility.
444-
*/
388+
/** Conversion from IArray to immutable.ArraySeq */
445389
implicit def wrapBooleanIArray(arr: IArray[Boolean]): ArraySeq.ofBoolean =
446390
mapNull(arr, new ArraySeq.ofBoolean(arr.asInstanceOf[Array[Boolean]]))
447391

448-
/** Conversion from IArray to immutable.ArraySeq.
449-
*
450-
* Note: Both the parameter and the return type are non-nullable. However, if a null
451-
* reference is passed explicitly, this method will still return null. We intentionally
452-
* keep this signature to discourage passing nulls implicitly while preserving the
453-
* previous behavior for backward compatibility.
454-
*/
392+
/** Conversion from IArray to immutable.ArraySeq */
455393
implicit def wrapUnitIArray(arr: IArray[Unit]): ArraySeq.ofUnit =
456394
mapNull(arr, new ArraySeq.ofUnit(arr.asInstanceOf[Array[Unit]]))
457395

library/src/scala/StringContext.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ case class StringContext(parts: String*) {
9595
object s {
9696
/** The simple string matcher.
9797
*
98-
* Attempts to match the input string to the given interpolated patterns via
98+
* Attempts to match the input string to the given interpolated patterns via
9999
* a naive globbing, that is the reverse of the simple interpolator.
100100
*
101101
* Here is an example usage:
@@ -206,7 +206,7 @@ object StringContext {
206206
* separated by wildcards
207207
* @param input The input you wish to match against
208208
* @return None if there is no match, Some containing the sequence of matched
209-
* wildcard strings if there is a match
209+
* wildcard strings if there is a match
210210
*/
211211
def glob(patternChunks: Seq[String], input: String): Option[Seq[String]] = {
212212
var patternIndex = 0
@@ -317,7 +317,7 @@ object StringContext {
317317
val len = src.length()
318318
def loop(uindex: Int): (Char, Int) = {
319319
def loopCP(dindex: Int, codepoint: Int): (Char, Int) = {
320-
//supports BMP + surrogate escapes
320+
//supports BMP + surrogate escapes
321321
//but only in four hex-digit code units (uxxxx)
322322
if(dindex >= 4) {
323323
val usRead = uindex - startindex
@@ -475,4 +475,3 @@ object StringContext {
475475
+") for interpolated string with "+ parts.length +" parts")
476476

477477
}
478-

library/src/scala/collection/JavaConverters.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ object JavaConverters extends AsJavaConverters with AsScalaConverters {
110110
@deprecated("Use `asJava` instead", "2.13.0")
111111
def mapAsJavaConcurrentMap[K, V](m: concurrent.Map[K, V]): juc.ConcurrentMap[K, V] = asJava(m)
112112

113+
113114
@deprecated("Use `asScala` instead", "2.13.0")
114115
def asScalaIterator[A](i: ju.Iterator[A]): Iterator[A] = asScala(i)
115116

library/src/scala/collection/convert/AsJavaConverters.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import scala.{unchecked => uc}
2424

2525
/** Defines converter methods from Scala to Java collections.
2626
* These methods are available through the [[scala.jdk.javaapi.CollectionConverters]] object.
27+
*
28+
* Note: Both the parameter and the return type are non-nullable. However, if a null
29+
* reference is passed explicitly, this method will still return null. We intentionally
30+
* keep this signature to discourage passing nulls implicitly while preserving the
31+
* previous behavior for backward compatibility.
2732
*/
2833
trait AsJavaConverters {
2934
import JavaCollectionWrappers._

library/src/scala/collection/convert/AsScalaConverters.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import scala.{unchecked => uc}
2525

2626
/** Defines converter methods from Java to Scala collections.
2727
* These methods are available through the [[scala.jdk.javaapi.CollectionConverters]] object.
28+
*
29+
* Note: Both the parameter and the return type are non-nullable. However, if a null
30+
* reference is passed explicitly, this method will still return null. We intentionally
31+
* keep this signature to discourage passing nulls implicitly while preserving the
32+
* previous behavior for backward compatibility.
2833
*/
2934
trait AsScalaConverters {
3035
import JavaCollectionWrappers._

0 commit comments

Comments
 (0)