Skip to content

Commit a0cb8f7

Browse files
committed
Merge #23099
Should fail because of explicit-nulls
2 parents 5064bde + 7a75a09 commit a0cb8f7

File tree

573 files changed

+95031
-0
lines changed

Some content is hidden

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

573 files changed

+95031
-0
lines changed

library/src/rootdoc.txt

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
This is the documentation for the Scala standard library.
2+
3+
== Package structure ==
4+
5+
The [[scala]] package contains core types like [[scala.Int `Int`]], [[scala.Float `Float`]], [[scala.Array `Array`]]
6+
or [[scala.Option `Option`]] which are accessible in all Scala compilation units without explicit qualification or
7+
imports.
8+
9+
Notable packages include:
10+
11+
- [[scala.collection `scala.collection`]] and its sub-packages contain Scala's collections framework
12+
- [[scala.collection.immutable `scala.collection.immutable`]] - Immutable, sequential data-structures such as
13+
[[scala.collection.immutable.Vector `Vector`]], [[scala.collection.immutable.List `List`]],
14+
[[scala.collection.immutable.Range `Range`]], [[scala.collection.immutable.HashMap `HashMap`]] or
15+
[[scala.collection.immutable.HashSet `HashSet`]]
16+
- [[scala.collection.mutable `scala.collection.mutable`]] - Mutable, sequential data-structures such as
17+
[[scala.collection.mutable.ArrayBuffer `ArrayBuffer`]],
18+
[[scala.collection.mutable.StringBuilder `StringBuilder`]],
19+
[[scala.collection.mutable.HashMap `HashMap`]] or [[scala.collection.mutable.HashSet `HashSet`]]
20+
- [[scala.collection.concurrent `scala.collection.concurrent`]] - Mutable, concurrent data-structures such as
21+
[[scala.collection.concurrent.TrieMap `TrieMap`]]
22+
- [[scala.concurrent `scala.concurrent`]] - Primitives for concurrent programming such as
23+
[[scala.concurrent.Future `Futures`]] and [[scala.concurrent.Promise `Promises`]]
24+
- [[scala.io `scala.io`]] - Input and output operations
25+
- [[scala.math `scala.math`]] - Basic math functions and additional numeric types like
26+
[[scala.math.BigInt `BigInt`]] and [[scala.math.BigDecimal `BigDecimal`]]
27+
- [[scala.sys `scala.sys`]] - Interaction with other processes and the operating system
28+
- [[scala.util.matching `scala.util.matching`]] - [[scala.util.matching.Regex Regular expressions]]
29+
30+
Other packages exist. See the complete list on the right.
31+
32+
Additional parts of the standard library are shipped as separate libraries. These include:
33+
34+
- [[https://www.scala-lang.org/api/current/scala-reflect/scala/reflect/index.html `scala.reflect`]] - Scala's reflection API (scala-reflect.jar)
35+
- [[https://github.com/scala/scala-xml `scala.xml`]] - XML parsing, manipulation, and serialization (scala-xml.jar)
36+
- [[https://github.com/scala/scala-parallel-collections `scala.collection.parallel`]] - Parallel collections (scala-parallel-collections.jar)
37+
- [[https://github.com/scala/scala-parser-combinators `scala.util.parsing`]] - Parser combinators (scala-parser-combinators.jar)
38+
- [[https://github.com/scala/scala-swing `scala.swing`]] - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)
39+
40+
== Automatic imports ==
41+
42+
Identifiers in the scala package and the [[scala.Predef `scala.Predef`]] object are always in scope by default.
43+
44+
Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, `List` is an alias for
45+
[[scala.collection.immutable.List `scala.collection.immutable.List`]].
46+
47+
Other aliases refer to classes provided by the underlying platform. For example, on the JVM, `String` is an alias for `java.lang.String`.

library/src/scala/AnyVal.scala

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala
14+
15+
/** `AnyVal` is the root class of all ''value types'', which describe values
16+
* not implemented as objects in the underlying host system. Value classes
17+
* are specified in Scala Language Specification, section 12.2.
18+
*
19+
* The standard implementation includes nine `AnyVal` subtypes:
20+
*
21+
* [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]],
22+
* [[scala.Short]], and [[scala.Byte]] are the ''numeric value types''.
23+
*
24+
* [[scala.Unit]] and [[scala.Boolean]] are the ''non-numeric value types''.
25+
*
26+
* Other groupings:
27+
*
28+
* - The ''subrange types'' are [[scala.Byte]], [[scala.Short]], and [[scala.Char]].
29+
* - The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]].
30+
* - The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
31+
*
32+
* A subclass of `AnyVal` is called a ''user-defined value class''
33+
* and is treated specially by the compiler. Properly-defined user value classes provide a way
34+
* to improve performance on user-defined types by avoiding object allocation at runtime, and by
35+
* replacing virtual method invocations with static method invocations.
36+
*
37+
* User-defined value classes which avoid object allocation...
38+
*
39+
* - must have a single `val` parameter that is the underlying runtime representation.
40+
* - can define `def`s, but no `val`s, `var`s, or nested `trait`s, `class`es or `object`s.
41+
* - typically extend no other trait apart from `AnyVal`.
42+
* - cannot be used in type tests or pattern matching.
43+
* - may not override `equals` or `hashCode` methods.
44+
*
45+
* A minimal example:
46+
* {{{
47+
* class Wrapper(val underlying: Int) extends AnyVal {
48+
* def foo: Wrapper = new Wrapper(underlying * 19)
49+
* }
50+
* }}}
51+
*
52+
* It's important to note that user-defined value classes are limited, and in some circumstances,
53+
* still must allocate a value class instance at runtime. These limitations and circumstances are
54+
* explained in greater detail in the [[https://docs.scala-lang.org/overviews/core/value-classes.html Value Classes and Universal Traits]].
55+
*/
56+
abstract class AnyVal extends Any {
57+
def getClass(): Class[_ <: AnyVal] = null
58+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala
14+
15+
/** A common supertype for companion classes of primitive types.
16+
*
17+
* A common trait for /companion/ objects of primitive types comes handy
18+
* when parameterizing code on types. For instance, the specialized
19+
* annotation is passed a sequence of types on which to specialize:
20+
* {{{
21+
* class Tuple1[@specialized(Unit, Int, Double) T]
22+
* }}}
23+
*
24+
*/
25+
private[scala] trait AnyValCompanion extends Specializable { }

library/src/scala/App.scala

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc. dba Akka
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala
14+
15+
import java.lang.System.{currentTimeMillis => currentTime}
16+
17+
import scala.annotation.nowarn
18+
import scala.collection.mutable.ListBuffer
19+
20+
/** The `App` trait can be used to quickly turn objects
21+
* into executable programs. Here is an example:
22+
* {{{
23+
* object Main extends App {
24+
* Console.println("Hello World: " + (args mkString ", "))
25+
* }
26+
* }}}
27+
*
28+
* No explicit `main` method is needed. Instead,
29+
* the whole class body becomes the “main method”.
30+
*
31+
* `args` returns the current command line arguments as an array.
32+
*
33+
* ==Caveats==
34+
*
35+
* '''''It should be noted that this trait is implemented using the [[DelayedInit]]
36+
* functionality, which means that fields of the object will not have been initialized
37+
* before the main method has been executed.'''''
38+
*
39+
* Future versions of this trait will no longer extend `DelayedInit`.
40+
*
41+
* In Scala 3, the `DelayedInit` feature was dropped. `App` exists only in a limited form
42+
* that also does not support command line arguments and will be deprecated in the future.
43+
*
44+
* [[https://docs.scala-lang.org/scala3/book/methods-main-methods.html @main]] methods are the
45+
* recommended scheme to generate programs that can be invoked from the command line in Scala 3.
46+
*
47+
* {{{
48+
* @main def runMyProgram(args: String*): Unit = {
49+
* // your program here
50+
* }
51+
* }}}
52+
*
53+
* If programs need to cross-build between Scala 2 and Scala 3, it is recommended to use an
54+
* explicit `main` method:
55+
* {{{
56+
* object Main {
57+
* def main(args: Array[String]): Unit = {
58+
* // your program here
59+
* }
60+
* }
61+
* }}}
62+
*/
63+
@nowarn("""cat=deprecation&origin=scala\.DelayedInit""")
64+
trait App extends DelayedInit {
65+
66+
/** The time when the execution of this program started, in milliseconds since 1
67+
* January 1970 UTC. */
68+
final val executionStart: Long = currentTime
69+
70+
/** The command line arguments passed to the application's `main` method.
71+
*/
72+
protected final def args: Array[String] = _args
73+
74+
private[this] var _args: Array[String] = _
75+
76+
private[this] val initCode = new ListBuffer[() => Unit]
77+
78+
/** The init hook. This saves all initialization code for execution within `main`.
79+
* This method is normally never called directly from user code.
80+
* Instead it is called as compiler-generated code for those classes and objects
81+
* (but not traits) that inherit from the `DelayedInit` trait and that do not
82+
* themselves define a `delayedInit` method.
83+
* @param body the initialization code to be stored for later execution
84+
*/
85+
@deprecated("the delayedInit mechanism will disappear", "2.11.0")
86+
override def delayedInit(body: => Unit): Unit = {
87+
initCode += (() => body)
88+
}
89+
90+
/** The main method.
91+
* This stores all arguments so that they can be retrieved with `args`
92+
* and then executes all initialization code segments in the order in which
93+
* they were passed to `delayedInit`.
94+
* @param args the arguments passed to the main method
95+
*/
96+
final def main(args: Array[String]) = {
97+
this._args = args
98+
for (proc <- initCode) proc()
99+
if (util.Properties.propIsSet("scala.time")) {
100+
val total = currentTime - executionStart
101+
Console.println("[total " + total + "ms]")
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)