summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile2
-rw-r--r--build.sbt1
-rwxr-xr-xbuild.xml40
-rw-r--r--spec/05-classes-and-objects.md26
-rw-r--r--spec/15-changelog.md260
-rw-r--r--src/compiler/scala/reflect/quasiquotes/Holes.scala2
-rw-r--r--src/compiler/scala/tools/nsc/PhaseAssembly.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala52
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala13
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala31
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala8
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/ByteCodeRepository.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala4
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaParsers.scala24
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Delambdafy.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/Logic.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala2
-rw-r--r--src/library/scala/collection/immutable/Stream.scala2
-rw-r--r--src/library/scala/collection/immutable/Vector.scala17
-rw-r--r--src/reflect/scala/reflect/internal/ClassfileConstants.scala13
-rw-r--r--src/reflect/scala/reflect/internal/ReificationSupport.scala2
-rw-r--r--src/reflect/scala/reflect/internal/tpe/TypeMaps.scala2
-rw-r--r--src/repl-jline/scala/tools/nsc/interpreter/jline/FileBackedHistory.scala (renamed from src/repl/scala/tools/nsc/interpreter/session/FileBackedHistory.scala)35
-rw-r--r--src/repl-jline/scala/tools/nsc/interpreter/jline/JLineDelimiter.scala25
-rw-r--r--src/repl-jline/scala/tools/nsc/interpreter/jline/JLineHistory.scala77
-rw-r--r--src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala143
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Delimited.scala41
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala61
-rw-r--r--src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala2
-rw-r--r--src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala1
-rw-r--r--src/repl/scala/tools/nsc/interpreter/JLineReader.scala75
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Parsed.scala19
-rw-r--r--src/repl/scala/tools/nsc/interpreter/Tabulators.scala (renamed from src/repl/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala)59
-rw-r--r--src/repl/scala/tools/nsc/interpreter/session/History.scala3
-rw-r--r--src/repl/scala/tools/nsc/interpreter/session/JLineHistory.scala49
-rw-r--r--src/repl/scala/tools/nsc/interpreter/session/SimpleHistory.scala12
-rw-r--r--src/repl/scala/tools/nsc/interpreter/session/package.scala5
-rw-r--r--src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala2
-rw-r--r--src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala2
-rw-r--r--test/files/jvm/unreachable/Test.scala2
-rw-r--r--test/files/neg/t3995.scala2
-rw-r--r--test/files/neg/t8237-default.scala2
-rw-r--r--test/files/neg/t8463.scala2
-rw-r--r--test/files/pos/SI-4012-b.scala2
-rw-r--r--test/files/pos/delambdafy-patterns.scala2
-rw-r--r--test/files/pos/t7200b.scala2
-rw-r--r--test/files/run/deeps.scala2
-rw-r--r--test/files/run/finally.scala2
-rw-r--r--test/files/run/iq.scala2
-rw-r--r--test/files/run/names-defaults.scala2
-rw-r--r--test/files/run/nullable-lazyvals.scala2
-rw-r--r--test/files/run/t6240-universe-code-gen.scala4
-rw-r--r--test/files/run/t7582.check5
-rw-r--r--test/files/run/t7582/InlineHolder.scala3
-rw-r--r--test/files/run/t7582b.check5
-rw-r--r--test/files/run/t7582b/InlineHolder.scala3
-rw-r--r--test/files/run/t8601-closure-elim.scala2
-rw-r--r--test/files/run/t8708_b/Test_2.scala2
-rw-r--r--test/files/run/t9359.check18
-rw-r--r--test/files/run/t9359/A_1.java19
-rw-r--r--test/files/run/t9359/B_2.java19
-rw-r--r--test/files/run/t9359/Test_2.scala28
-rw-r--r--test/files/specialized/constant_lambda.scala2
-rw-r--r--test/scaladoc/run/groups.scala2
69 files changed, 752 insertions, 516 deletions
diff --git a/Gemfile b/Gemfile
index 6921f792c3..b74696e550 100644
--- a/Gemfile
+++ b/Gemfile
@@ -4,4 +4,4 @@ source "https://rubygems.org"
gem "jekyll", "2.5.3"
gem "rouge"
# gem 's3_website'
-# gem 'redcarpet'
+gem "redcarpet", "3.2.3"
diff --git a/build.sbt b/build.sbt
index e960a4c3d2..1e3bef2541 100644
--- a/build.sbt
+++ b/build.sbt
@@ -191,6 +191,7 @@ lazy val interactive = configureAsSubproject(project)
.settings(disableDocsAndPublishingTasks: _*)
.dependsOn(compiler)
+// TODO: SI-9339 embed shaded copy of jline & its interface (see #4563)
lazy val repl = configureAsSubproject(project)
.settings(
libraryDependencies += jlineDep,
diff --git a/build.xml b/build.xml
index 421646a2b0..589e1931b8 100755
--- a/build.xml
+++ b/build.xml
@@ -275,6 +275,10 @@ TODO:
<dependency groupId="biz.aQute" artifactId="bnd" version="1.50.0"/>
</artifact:dependencies>
+ <artifact:dependencies pathId="jarjar.classpath">
+ <dependency groupId="com.googlecode.jarjar" artifactId="jarjar" version="1.3"/>
+ </artifact:dependencies>
+
<!-- JUnit -->
<property name="junit.version" value="4.11"/>
<artifact:dependencies pathId="junit.classpath" filesetId="junit.fileset">
@@ -696,7 +700,7 @@ TODO:
<property name="partest-javaagent.description" value="Scala Compiler Testing Tool (compiler-specific java agent)"/>
<!-- projects without project-specific options: forkjoin, manual, bin, repl -->
- <for list="actors,compiler,interactive,scaladoc,library,parser-combinators,partest,partest-extras,partest-javaagent,reflect,scalap,swing,xml,continuations-plugin,continuations-library" param="project">
+ <for list="actors,compiler,interactive,scaladoc,library,parser-combinators,partest,partest-extras,partest-javaagent,reflect,scalap,swing,xml,continuations-plugin,continuations-library,repl-jline" param="project">
<sequential>
<!-- description is mandatory -->
<init-project-prop project="@{project}" name="package" default=""/> <!-- used by mvn-package, copy-bundle, make-bundle -->
@@ -799,6 +803,11 @@ TODO:
<path id="quick.repl.build.path">
<path refid="quick.compiler.build.path"/>
<pathelement location="${build-quick.dir}/classes/repl"/>
+ </path>
+
+ <path id="quick.repl-jline.build.path">
+ <path refid="quick.repl.build.path"/>
+ <pathelement location="${build-quick.dir}/classes/repl-jline"/>
<path refid="repl.deps.classpath"/>
</path>
@@ -873,6 +882,8 @@ TODO:
<fileset dir="${build-quick.dir}/classes/actors"/>
</path>
+ <path id="pack.repl-jline.files"> <fileset dir="${build-quick.dir}/classes/repl-jline"/> </path>
+
<path id="pack.compiler.files">
<fileset dir="${build-quick.dir}/classes/compiler"/>
@@ -1076,6 +1087,7 @@ TODO:
</patternset>
<taskdef resource="scala/tools/ant/sabbus/antlib.xml" classpathref="starr.compiler.path"/>
+ <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpathref="jarjar.classpath" />
</target>
<!-- ===========================================================================
@@ -1157,7 +1169,31 @@ TODO:
<staged-build with="locker" stage="quick" project="compiler"/> </target>
<target name="quick.repl" depends="quick.comp">
- <staged-build with="locker" stage="quick" project="repl"/> </target>
+ <staged-build with="locker" stage="quick" project="repl"/>
+ <staged-build with="locker" stage="quick" project="repl-jline"/>
+
+ <staged-pack project="repl-jline"/>
+
+ <!-- make jline_embedded jar with classes of repl-jline and jline, then shade-->
+ <jarjar jarfile="${build-pack.dir}/${repl-jline.targetdir}/scala-repl-jline-embedded.jar" whenmanifestonly="fail">
+ <zipfileset src="${jline:jline:jar}"/>
+ <zipfileset src="${build-pack.dir}/${repl-jline.targetdir}/${repl-jline.targetjar}"/>
+
+ <rule pattern="org.fusesource.**" result="scala.tools.fusesource_embedded.@1"/>
+ <rule pattern="jline.**" result="scala.tools.jline_embedded.@1"/>
+ <rule pattern="scala.tools.nsc.interpreter.jline.**" result="scala.tools.nsc.interpreter.jline_embedded.@1"/>
+ <keep pattern="scala.tools.**"/>
+ </jarjar>
+
+ <!-- unzip jar to repl's class dir to obtain
+ - standard repl-jline
+ - a shaded repl-jline (scala/tools/nsc/interpreter/jline_embedded) & jline (scala.tools.jline_embedded)
+ -->
+ <copy todir="${build-quick.dir}/classes/repl">
+ <zipfileset src="${build-pack.dir}/${repl-jline.targetdir}/${repl-jline.targetjar}"/>
+ <zipfileset src="${build-pack.dir}/${repl-jline.targetdir}/scala-repl-jline-embedded.jar"/>
+ </copy>
+ </target>
<target name="quick.scaladoc" depends="quick.comp">
<staged-build with="locker" stage="quick" project="scaladoc" version="scaladoc"/> </target>
diff --git a/spec/05-classes-and-objects.md b/spec/05-classes-and-objects.md
index 8be792d3cb..cff5442641 100644
--- a/spec/05-classes-and-objects.md
+++ b/spec/05-classes-and-objects.md
@@ -501,14 +501,13 @@ declaration in a template. Such members can be accessed only from
within the directly enclosing template and its companion module or
[companion class](#object-definitions).
-The modifier can be _qualified_ with an identifier $C$ (e.g.
-`private[$C$]`) that must denote a class or package
-enclosing the definition. Members labeled with such a modifier are
-accessible respectively only from code inside the package $C$ or only
-from code inside the class $C$ and its
+A `private` modifier can be _qualified_ with an identifier $C$ (e.g.
+`private[$C$]`) that must denote a class or package enclosing the definition.
+Members labeled with such a modifier are accessible respectively only from code
+inside the package $C$ or only from code inside the class $C$ and its
[companion module](#object-definitions).
-An different form of qualification is `private[this]`. A member
+A different form of qualification is `private[this]`. A member
$M$ marked with this modifier is called _object-protected_; it can be accessed only from within
the object in which it is defined. That is, a selection $p.M$ is only
legal if the prefix is `this` or `$O$.this`, for some
@@ -533,11 +532,10 @@ Protected members of a class can be accessed from within
- all templates that have the defining class as a base class,
- the companion module of any of those classes.
-A `protected` modifier can be qualified with an
-identifier $C$ (e.g. `protected[$C$]`) that must denote a
-class or package enclosing the definition. Members labeled with such
-a modifier are also accessible respectively from all code inside the
-package $C$ or from all code inside the class $C$ and its
+A `protected` modifier can be qualified with an identifier $C$ (e.g.
+`protected[$C$]`) that must denote a class or package enclosing the definition.
+Members labeled with such a modifier are also accessible respectively from all
+code inside the package $C$ or from all code inside the class $C$ and its
[companion module](#object-definitions).
A protected identifier $x$ may be used as a member name in a selection
@@ -744,7 +742,7 @@ which when applied to parameters conforming to types $\mathit{ps}$
initializes instances of type `$c$[$\mathit{tps}\,$]` by evaluating the template
$t$.
-###### Example
+###### Example – `val` and `var` parameters
The following example illustrates `val` and `var` parameters of a class `C`:
```scala
@@ -753,7 +751,7 @@ val c = new C(1, "abc", List())
c.z = c.y :: c.z
```
-### Example Private Constructor
+###### Example – Private Constructor
The following class can be created only from its companion module.
```scala
@@ -835,7 +833,7 @@ This defines a class `LinkedList` with three constructors. The
second constructor constructs an singleton list, while the
third one constructs a list with a given head and tail.
-## Case Classes
+### Case Classes
```ebnf
TmplDef ::= `case' `class' ClassDef
diff --git a/spec/15-changelog.md b/spec/15-changelog.md
index 54310c921c..3c8739359a 100644
--- a/spec/15-changelog.md
+++ b/spec/15-changelog.md
@@ -122,8 +122,8 @@ when compiling with `-target:jvm-1.4`, a Scala type such as
#### Changes to Case Classes
-The Scala compiler generates now for every case class a companion
-extractor object (). For instance, given the case class:
+The Scala compiler generates a [companion extractor object for every case class]
+(05-classes-and-objects.html#case-classes) now. For instance, given the case class:
case class X(elem: String)
@@ -152,8 +152,9 @@ _(30-Nov-2007)_
#### Mutable variables introduced by pattern binding
-Mutable variables can now be introduced by a pattern matching definition
-(), just like values can. Examples:
+[Mutable variables can now be introduced by a pattern matching definition]
+(04-basic-declarations-and-definitions.html#variable-declarations-and-definitions),
+just like values can. Examples:
var (x, y) = if (positive) (1, 2) else (-1, -3)
var hd :: tl = mylist
@@ -161,7 +162,7 @@ Mutable variables can now be introduced by a pattern matching definition
#### Self-types
Self types can now be introduced without defining an alias name for
-`this` (). Example:
+[`this`](05-classes-and-objects.html#templates). Example:
class C {
type T <: Trait
@@ -175,8 +176,8 @@ _(27-July-2007)_
#### Existential types
-It is now possible to define existential types (). An existential type
-has the form `T forSome {Q}` where `Q` is a sequence of value and/or
+It is now possible to define [existential types](03-types.html#existential-types).
+An existential type has the form `T forSome {Q}` where `Q` is a sequence of value and/or
type declarations. Given the class definitions
class Ref[T]
@@ -189,8 +190,9 @@ one may for example write the following existential types
#### Lazy values
-It is now possible to define lazy value declarations using the new
-modifier `lazy` (). A `lazy` value definition evaluates its right hand
+It is now possible to define lazy value declarations using the new modifier
+[`lazy`](04-basic-declarations-and-definitions.html#value-declarations-and-definitions).
+A `lazy` value definition evaluates its right hand
side \\(e\\) the first time the value is accessed. Example:
import compat.Platform._
@@ -203,8 +205,8 @@ side \\(e\\) the first time the value is accessed. Example:
#### Structural types
-It is now possible to declare structural types using type refinements
-(). For example:
+It is now possible to declare structural types using [type refinements]
+(03-types.html#compound-types). For example:
class File(name: String) {
def getName(): String = name
@@ -230,10 +232,13 @@ Changes in Version 2.5
_(02-May-2007)_
-#### Type constructor polymorphism[^1]
+#### Type constructor polymorphism
-Type parameters () and abstract type members () can now also abstract
-over type constructors ().
+_Implemented by Adriaan Moors_
+
+[Type parameters](04-basic-declarations-and-definitions.html#type-parameters)
+and abstract
+[type members](04-basic-declarations-and-definitions.html#type-declarations-and-type-aliases) can now also abstract over [type constructors](03-types.html#type-constructors).
This allows a more precise `Iterable` interface:
@@ -254,8 +259,9 @@ over a certain structure (e.g., a `List`) will yield the same structure
#### Early object initialization
-It is now possible to initialize some fields of an object before any
-parent constructors are called (). This is particularly useful for
+[Early object initialization](05-classes-and-objects.html#early-definitions)
+makes it possible to initialize some fields of an object before any
+parent constructors are called. This is particularly useful for
traits, which do not have normal constructor parameters. Example:
trait Greeting {
@@ -273,10 +279,11 @@ called. Therefore, field `msg` in class is properly initialized to .
#### For-comprehensions, revised
-The syntax of for-comprehensions has changed (). In the new syntax,
-generators do not start with a anymore, but filters start with an (and
-are called guards). A semicolon in front of a guard is optional. For
-example:
+The syntax of [for-comprehensions](06-expressions.html#for-comprehensions-and-for-loops)
+has changed.
+In the new syntax, generators do not start with a `val` anymore, but filters
+start with an `if` (and are called guards).
+A semicolon in front of a guard is optional. For example:
for (val x <- List(1, 2, 3); x % 2 == 0) println(x)
@@ -288,8 +295,9 @@ The old syntax is still available but will be deprecated in the future.
#### Implicit anonymous functions
-It is now possible to define anonymous functions using underscores in
-parameter position (). For instance, the expressions in the left column
+It is now possible to define [anonymous functions using underscores]
+(06-expressions.html#placeholder-syntax-for-anonymous-functions) in
+parameter position. For instance, the expressions in the left column
are each function values which expand to the anonymous functions on
their right.
@@ -300,8 +308,8 @@ their right.
_.map(f) x => x.map(f)
_.map(_ + 1) x => x.map(y => y + 1)
-As a special case (), a partially unapplied method is now designated
- `m _`   instead of the previous notation  `&m`.
+As a special case, a [partially unapplied method](06-expressions.html#method-values)
+is now designated `m _`   instead of the previous notation  `&m`.
The new notation will displace the special syntax forms `.m()` for
abstracting over method receivers and `&m` for treating an unapplied
@@ -310,8 +318,9 @@ still available, but they will be deprecated in the future.
#### Pattern matching anonymous functions, refined
-It is now possible to use case clauses to define a function value
-directly for functions of arities greater than one (). Previously, only
+It is now possible to use [case clauses to define a function value]
+(08-pattern-matching.html#pattern-matching-anonymous-functions)
+directly for functions of arities greater than one. Previously, only
unary functions could be defined that way. Example:
def scalarProduct(xs: Array[Double], ys: Array[Double]) =
@@ -326,8 +335,9 @@ _(09-Mar-2007)_
#### Object-local private and protected
-The `private` and `protected` modifiers now accept a `[this]` qualifier
-(). A definition \\(M\\) which is labelled `private[this]` is private,
+The `private` and `protected` modifiers now accept a
+[`[this]` qualifier](05-classes-and-objects.html#modifiers).
+A definition \\(M\\) which is labelled `private[this]` is private,
and in addition can be accessed only from within the current object.
That is, the only legal prefixes for \\(M\\) are `this` or `$C$.this`.
Analogously, a definition \\(M\\) which is labelled `protected[this]` is
@@ -348,16 +358,17 @@ Analogously, for any sequence of expressions or patterns \\(x_1
#### Access modifiers for primary constructors
-The primary constructor of a class can now be marked or (). If such an
-access modifier is given, it comes between the name of the class and its
+The primary constructor of a class can now be marked [`private` or `protected`]
+(05-classes-and-objects.html#class-definitions).
+If such an access modifier is given, it comes between the name of the class and its
value parameters. Example:
class C[T] private (x: T) { ... }
#### Annotations
-The support for attributes has been extended and its syntax changed ().
-Attributes are now called <span>*annotations*</span>. The syntax has
+The support for attributes has been extended and its syntax changed.
+Attributes are now called [*annotations*](11-annotations.html). The syntax has
been changed to follow Java’s conventions, e.g. `@attribute` instead of
`[attribute]`. The old syntax is still available but will be deprecated
in the future.
@@ -373,12 +384,13 @@ symbol is accessed.
#### Decidable subtyping
The implementation of subtyping has been changed to prevent infinite
-recursions. Termination of subtyping is now ensured by a new restriction
-of class graphs to be finitary ().
+recursions.
+[Termination of subtyping](05-classes-and-objects.html#inheritance-closure)
+is now ensured by a new restriction of class graphs to be finitary.
#### Case classes cannot be abstract
-It is now explicitly ruled out that case classes can be abstract (). The
+It is now explicitly ruled out that case classes can be abstract. The
specification was silent on this point before, but did not explain how
abstract case classes were treated. The Scala compiler allowed the
idiom.
@@ -386,19 +398,21 @@ idiom.
#### New syntax for self aliases and self types
It is now possible to give an explicit alias name and/or type for the
-self reference (). For instance, in
+[self reference](05-classes-and-objects.html#templates) `this`. For instance, in
class C { self: D =>
...
}
-the name is introduced as an alias for within and the self type () of is
-assumed to be . This construct is introduced now in order to replace
+the name `self` is introduced as an alias for `this` within `C` and the
+[self type](05-classes-and-objects.html#class-definitions) of `C` is
+assumed to be `D`. This construct is introduced now in order to replace
eventually both the qualified this construct and the clause in Scala.
#### Assignment Operators
-It is now possible to combine operators with assignments (). Example:
+It is now possible to [combine operators with assignments]
+(06-expressions.html#assignment-operators). Example:
var x: int = 0
x += 1
@@ -410,8 +424,9 @@ _(23-Jan-2007)_
#### Extractors
-It is now possible to define patterns independently of case classes,
-using methods in extractor objects (). Here is an example:
+It is now possible to define patterns independently of case classes, using
+`unapply` methods in [extractor objects](08-pattern-matching.html#extractor-patterns).
+Here is an example:
object Twice {
def apply(x:Int): int = x*2
@@ -422,25 +437,26 @@ using methods in extractor objects (). Here is an example:
In the example, `Twice` is an extractor object with two methods:
-- The method is used to build even numbers.
+- The `apply` method is used to build even numbers.
-- The method is used to decompose an even number; it is in a sense the
- reverse of . `unapply` methods return option types: for a match that
- suceeds, for a match that fails. Pattern variables are returned as
- the elements of . If there are several variables, they are grouped
- in a tuple.
+- The `unapply` method is used to decompose an even number; it is in a sense
+ the reverse of `apply`. `unapply` methods return option types:
+ `Some(...)` for a match that suceeds, `None` for a match that fails.
+ Pattern variables are returned as the elements of `Some`.
+ If there are several variables, they are grouped in a tuple.
-In the second-to-last line, ’s method is used to construct a number . In
-the last line, is tested against the pattern . This pattern succeeds for
-even numbers and assigns to the variable one half of the number that was
-tested. The pattern match makes use of the method of object . More
-details on extractors can be found in the paper “Matching Objects with
+In the second-to-last line, `Twice`’s method is used to construct a number `x`.
+In the last line, `x` is tested against the pattern `Twice(n)`.
+This pattern succeeds for even numbers and assigns to the variable `n` one half
+of the number that was tested.
+The pattern match makes use of the `unapply` method of object `Twice`.
+More details on extractors can be found in the paper “Matching Objects with
Patterns” by Emir, Odersky and Williams.
#### Tuples
-A new lightweight syntax for tuples has been introduced (). For any
-sequence of types \\(T_1 , … , T_n\\),
+A new [lightweight syntax for tuples](06-expressions.html#tuples) has been introduced.
+For any sequence of types \\(T_1 , … , T_n\\),
\\(\{T_1 , … , T_n \}\\) is a shorthand for `Tuple$n$[$T_1 , … , T_n$]`.
@@ -451,8 +467,8 @@ Analogously, for any sequence of expressions or patterns \\(x_1, … , x_n\\),
#### Infix operators of greater arities
It is now possible to use methods which have more than one parameter as
-infix operators (). In this case, all method arguments are written as a
-normal parameter list in parentheses. Example:
+[infix operators](06-expressions.html#infix-operations). In this case, all
+method arguments are written as a normal parameter list in parentheses. Example:
class C {
def +(x: int, y: String) = ...
@@ -462,9 +478,9 @@ normal parameter list in parentheses. Example:
#### Deprecated attribute
-A new standard attribute `deprecated` is available (11-annotations.html#deprecation-annotations). If a member
-definition is marked with this attribute, any reference to the member
-will cause a “deprecated” warning message to be emitted.
+A new standard attribute [`deprecated`](11-annotations.html#deprecation-annotations)
+is available. If a member definition is marked with this attribute, any
+reference to the member will cause a “deprecated” warning message to be emitted.
Changes in Version 2.3
----------------------
@@ -473,20 +489,23 @@ _(23-Nov-2006)_
#### Procedures
-A simplified syntax for functions returning `unit` has been introduced
-(). Scala now allows the following shorthands:
+A simplified syntax for [methods returning `unit`]
+(04-basic-declarations-and-definitions.html#procedures) has been introduced.
+Scala now allows the following shorthands:
`def f(params)` \\(\mbox{for}\\) `def f(params): unit`
`def f(params) { ... }` \\(\mbox{for}\\) `def f(params): unit = { ... }`
#### Type Patterns
-The syntax of types in patterns has been refined (). Scala now
-distinguishes between type variables (starting with a lower case letter)
-and types as type arguments in patterns. Type variables are bound in the
-pattern. Other type arguments are, as in previous versions, erased. The
-Scala compiler will now issue an “unchecked” warning at places where
-type erasure might compromise type-safety.
+The [syntax of types in patterns](08-pattern-matching.html#type-patterns) has
+been refined.
+Scala now distinguishes between type variables (starting with a lower case
+letter) and types as type arguments in patterns.
+Type variables are bound in the pattern.
+Other type arguments are, as in previous versions, erased.
+The Scala compiler will now issue an “unchecked” warning at places where type
+erasure might compromise type-safety.
#### Standard Types
@@ -505,43 +524,43 @@ _(23-Aug-2006)_
#### Visibility Qualifier for protected
-Protected members can now have a visibility qualifier (), e.g.
-`protected[<qualifier>]`. In particular, one can now simulate package
-protected access as in Java writing
+Protected members can now have a visibility qualifier, e.g.
+[`protected[<qualifier>]`](05-classes-and-objects.html#protected).
+In particular, one can now simulate package protected access as in Java writing
protected[P] def X ...
-where would name the package containing .
+where would name the package containing `X`.
#### Relaxation of Private Acess
-Private members of a class can now be referenced from the companion
-module of the class and vice versa ()
+[Private members of a class](05-classes-and-objects.html#private) can now be
+referenced from the companion module of the class and vice versa.
#### Implicit Lookup
-The lookup method for implicit definitions has been generalized (). When
-searching for an implicit definition matching a type \\(T\\), now are
-considered
+The lookup method for [implicit definitions](07-implicits.html#implicit-parameters)
+has been generalized.
+When searching for an implicit definition matching a type \\(T\\), now are considered
1. all identifiers accessible without prefix, and
2. all members of companion modules of classes associated with \\(T\\).
-(The second clause is more general than before). Here, a class is
-<span>*associated*</span> with a type \\(T\\) if it is referenced by
-some part of \\(T\\), or if it is a base class of some part of \\(T\\).
+(The second clause is more general than before). Here, a class is _associated_
+with a type \\(T\\) if it is referenced by some part of \\(T\\), or if it is a
+base class of some part of \\(T\\).
For instance, to find implicit members corresponding to the type
HashSet[List[Int], String]
-one would now look in the companion modules (aka static parts) of , , ,
-and . Before, it was just the static part of .
+one would now look in the companion modules (aka static parts) of `HashSet`,
+`List`, `Int`, and `String`. Before, it was just the static part of .
#### Tightened Pattern Match
-A typed pattern match with a singleton type now tests whether the
-selector value is reference-equal to p (). Example:
+A typed [pattern match with a singleton type `p.type`](08-pattern-matching.html#type-patterns)
+now tests whether the selector value is reference-equal to `p`. Example:
val p = List(1, 2, 3)
val q = List(1, 2)
@@ -551,8 +570,8 @@ selector value is reference-equal to p (). Example:
case _: q.type => Console.println("q")
}
-This will match the second case and hence will print “”. Before, the
-singleton types were erased to , and therefore the first case would have
+This will match the second case and hence will print “q”. Before, the
+singleton types were erased to `List`, and therefore the first case would have
matched, which is non-sensical.
Changes in Version 2.1.7
@@ -562,8 +581,8 @@ _(19-Jul-2006)_
#### Multi-Line string literals
-It is now possible to write multi-line string-literals enclosed in
-triple quotes (). Example:
+It is now possible to write [multi-line string-literals]
+(01-lexical-syntax.html#string-literals) enclosed in triple quotes. Example:
"""this is a
multi-line
@@ -574,13 +593,14 @@ string literals.
#### Closure Syntax
-The syntax of closures has been slightly restricted (). The form
+The syntax of [closures](06-expressions.html#anonymous-functions)
+has been slightly restricted. The form
x: T => E
is valid only when enclosed in braces, i.e.  `{ x: T => E }`. The
following is illegal, because it might be read as the value x typed with
-the type T =\> E:
+the type `T => E`:
val f = x: T => E
@@ -596,8 +616,9 @@ _(24-May-2006)_
#### Class Literals
-There is a new syntax for class literals (): For any class type \\(C\\),
-`classOf[$C$]` designates the run-time representation of \\(C\\).
+There is a new syntax for [class literals](06-expressions.html#literals):
+For any class type \\(C\\), `classOf[$C$]` designates the run-time
+representation of \\(C\\).
Changes in Version 2.0
----------------------
@@ -612,14 +633,14 @@ changes.
#### New Keywords
The following three words are now reserved; they cannot be used as
-identifiers ()
+[identifiers](01-lexical-syntax.html#identifiers):
implicit match requires
#### Newlines as Statement Separators
-Newlines can now be used as statement separators in place of semicolons
-()
+[Newlines](http://www.scala-lang.org/files/archive/spec/2.11/)
+can now be used as statement separators in place of semicolons.
#### Syntax Restrictions
@@ -649,8 +670,8 @@ is no longer supported. A `with` connective is only allowed following an
class C extends AnyRef with M { ... } .
-However, assuming `M` is a trait (see [sec:traits]), it is also legal to
-write
+However, assuming `M` is a [trait](05-classes-and-objects.html#traits),
+it is also legal to write
class C extends M { ... }
@@ -665,7 +686,7 @@ where `S` is the superclass of `M`.
The only form of regular expression pattern that is currently supported
is a sequence pattern, which might end in a sequence wildcard . Example:
- case List(1, 2, _*) => ... // will match all lists starting with \code{1,2}.
+ case List(1, 2, _*) => ... // will match all lists starting with 1, 2, ...
It is at current not clear whether this is a permanent restriction. We
are evaluating the possibility of re-introducing full regular expression
@@ -686,7 +707,8 @@ old syntax is still available but is considered deprecated.
#### For-comprehensions
-For-comprehensions () now admit value and pattern definitions. Example:
+[For-comprehensions](06-expressions.html#for-comprehensions-and-for-loops)
+now admit value and pattern definitions. Example:
for {
val x <- List.range(1, 100)
@@ -700,8 +722,9 @@ for-comprehension.
#### Conversions
-The rules for implicit conversions of methods to functions () have been
-tightened. Previously, a parameterized method used as a value was always
+The rules for [implicit conversions of methods to functions]
+(06-expressions.html#method-conversions) have been tightened.
+Previously, a parameterized method used as a value was always
implicitly converted to a function. This could lead to unexpected
results when method arguments where forgotten. Consider for instance the
statement below:
@@ -750,10 +773,11 @@ instance, the `show` expression above will now be expanded to
show(x.toString()) .
Scala version 2.0 also relaxes the rules of overriding with respect to
-empty parameter lists. The revised definition of <span>*matching
-members*</span> () makes it now possible to override a method with an
+empty parameter lists. The revised definition of
+[_matching members_](05-classes-and-objects.html#class-members)
+makes it now possible to override a method with an
explicit, but empty parameter list `()` with a parameterless method, and
-<span>*vice versa*</span>. For instance, the following class definition
+_vice versa_. For instance, the following class definition
is now legal:
class C {
@@ -766,26 +790,29 @@ parameter list.
#### Class Parameters
-A class parameter may now be prefixed by `val` or `var` ().
+A [class parameter](05-classes-and-objects.html#class-definitions)
+may now be prefixed by `val` or `var`.
#### Private Qualifiers
Previously, Scala had three levels of visibility:
<span>*private*</span>, <span>*protected*</span> and
<span>*public*</span>. There was no way to restrict accesses to members
-of the current package, as in Java. Scala 2 now defines access
-qualifiers that let one express this level of visibility, among others.
-In the definition
+of the current package, as in Java.
+
+Scala 2 now defines [access qualifiers](05-classes-and-objects.html#modifiers)
+that let one express this level of visibility, among others. In the definition
private[C] def f(...)
access to `f` is restricted to all code within the class or package `C`
-(which must contain the definition of `f`) ()
+(which must contain the definition of `f`).
#### Changes in the Mixin Model
-The model which details mixin composition of classes has changed
-significantly. The main differences are:
+The model which details [mixin composition of classes]
+(05-classes-and-objects.html#templates) has changed significantly.
+The main differences are:
1. We now distinguish between <span>*traits*</span> that are used as
mixin classes and normal classes. The syntax of traits has been
@@ -802,22 +829,19 @@ significantly. The main differences are:
different mixins. This makes method overloading in Scala
conceptually the same as in Java.
-The new mixin model is explained in more detail in .
-
#### Implicit Parameters
Views in Scala 1.0 have been replaced by the more general concept of
-implicit parameters ()
+[implicit parameters](07-implicits.html#implicit-parameters).
#### Flexible Typing of Pattern Matching
The new version of Scala implements more flexible typing rules when it
-comes to pattern matching over heterogeneous class hierarchies (). A
-<span>*heterogeneous class hierarchy*</span> is one where subclasses
+comes to [pattern matching over heterogeneous class hierarchies]
+(08-pattern-matching.html#pattern-matching-expressions).
+A <span>*heterogeneous class hierarchy*</span> is one where subclasses
inherit a common superclass with different parameter types. With the new
rules in Scala version 2.0 one can perform pattern matches over such
hierarchies with more precise typings that keep track of the information
-gained by comparing the types of a selector and a matching pattern ().
+gained by comparing the types of a selector and a matching pattern.
This gives Scala capabilities analogous to guarded algebraic data types.
-
-[^1]: Implemented by Adriaan Moors
diff --git a/src/compiler/scala/reflect/quasiquotes/Holes.scala b/src/compiler/scala/reflect/quasiquotes/Holes.scala
index 6fa6b9b37a..47084fc317 100644
--- a/src/compiler/scala/reflect/quasiquotes/Holes.scala
+++ b/src/compiler/scala/reflect/quasiquotes/Holes.scala
@@ -151,7 +151,7 @@ trait Holes { self: Quasiquotes =>
else None
}
- /** Map high-rank unquotee onto an expression that eveluates as a list of given rank.
+ /** Map high-rank unquotee onto an expression that evaluates as a list of given rank.
*
* All possible combinations of representations are given in the table below:
*
diff --git a/src/compiler/scala/tools/nsc/PhaseAssembly.scala b/src/compiler/scala/tools/nsc/PhaseAssembly.scala
index 4b32aab5ee..ef9818c62d 100644
--- a/src/compiler/scala/tools/nsc/PhaseAssembly.scala
+++ b/src/compiler/scala/tools/nsc/PhaseAssembly.scala
@@ -226,7 +226,7 @@ trait PhaseAssembly {
}
/** Given the phases set, will build a dependency graph from the phases set
- * Using the aux. method of the DependencyGraph to create nodes and egdes.
+ * Using the aux. method of the DependencyGraph to create nodes and edges.
*/
private def phasesSetToDepGraph(phsSet: mutable.HashSet[SubComponent]): DependencyGraph = {
val graph = new DependencyGraph()
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 137954b52d..3e23291e92 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1022,7 +1022,7 @@ abstract class GenICode extends SubComponent {
tree match {
case Literal(Constant(null)) if generatedType == NullReference && expectedType != UNIT =>
// literal null on the stack (as opposed to a boxed null, see SI-8233),
- // we can bypass `adapt` which would otherwise emitt a redundant [DROP, CONSTANT(null)]
+ // we can bypass `adapt` which would otherwise emit a redundant [DROP, CONSTANT(null)]
// except one case: when expected type is UNIT (unboxed) where we need to emit just a DROP
case _ =>
adapt(generatedType, expectedType, resCtx, tree.pos)
@@ -2108,7 +2108,7 @@ abstract class GenICode extends SubComponent {
/**
* Represent a label in the current method code. In order
* to support forward jumps, labels can be created without
- * having a deisgnated target block. They can later be attached
+ * having a designated target block. They can later be attached
* by calling `anchor`.
*/
class Label(val symbol: Symbol) {
diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala
index 058b6a161d..64c9901a3e 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala
@@ -387,7 +387,7 @@ abstract class TypeFlowAnalysis {
Moreover, it's often the case that the last CALL_METHOD of interest ("of interest" equates to "being tracked in `isOnWatchlist`) isn't the last instruction on the block.
There are cases where the typeflows computed past this `lastInstruction` are needed, and cases when they aren't.
- The reasoning behind this decsision is described in `populatePerimeter()`. All `blockTransfer()` needs to do (in order to know at which instruction it can stop)
+ The reasoning behind this decision is described in `populatePerimeter()`. All `blockTransfer()` needs to do (in order to know at which instruction it can stop)
is querying `isOnPerimeter`.
Upon visiting a CALL_METHOD that's an inlining candidate, the relevant pieces of information about the pre-instruction typestack are collected for future use.
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
index eadc404bee..dec5adc9aa 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
@@ -9,6 +9,7 @@ package backend.jvm
import scala.tools.nsc.Global
import scala.tools.nsc.backend.jvm.BTypes.{InternalName, MethodInlineInfo, InlineInfo}
import BackendReporting.ClassSymbolInfoFailureSI9111
+import scala.tools.asm
/**
* This trait contains code shared between GenBCode and GenASM that depends on types defined in
@@ -229,6 +230,44 @@ final class BCodeAsmCommon[G <: Global](val global: G) {
}
/**
+ * Reconstruct the classfile flags from a Java defined class symbol.
+ *
+ * The implementation of this method is slightly different that `javaFlags` in BTypesFromSymbols.
+ * The javaFlags method is primarily used to map Scala symbol flags to sensible classfile flags
+ * that are used in the generated classfiles. For example, all classes emitted by the Scala
+ * compiler have ACC_PUBLIC.
+ *
+ * When building a [[ClassBType]] from a Java class symbol, the flags in the type's `info` have
+ * to correspond exactly to the flags in the classfile. For example, if the class is package
+ * protected (i.e., it doesn't have the ACC_PUBLIC flag), this needs to be reflected in the
+ * ClassBType. For example, the inliner needs the correct flags for access checks.
+ *
+ * Class flags are listed here:
+ * https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-E.1
+ */
+ def javaClassfileFlags(classSym: Symbol): Int = {
+ assert(classSym.isJava, s"Expected Java class symbol, got ${classSym.fullName}")
+ import asm.Opcodes._
+ def enumFlags = ACC_ENUM | {
+ // Java enums have the `ACC_ABSTRACT` flag if they have a deferred method.
+ // We cannot trust `hasAbstractFlag`: the ClassfileParser adds `ABSTRACT` and `SEALED` to all
+ // Java enums for exhaustiveness checking.
+ val hasAbstractMethod = classSym.info.decls.exists(s => s.isMethod && s.isDeferred)
+ if (hasAbstractMethod) ACC_ABSTRACT else 0
+ }
+ GenBCode.mkFlags(
+ if (classSym.isPublic) ACC_PUBLIC else 0,
+ if (classSym.isFinal) ACC_FINAL else 0,
+ // see the link above. javac does the same: ACC_SUPER for all classes, but not interfaces.
+ if (classSym.isInterface) ACC_INTERFACE else ACC_SUPER,
+ // for Java enums, we cannot trust `hasAbstractFlag` (see comment in enumFlags)
+ if (!classSym.hasEnumFlag && classSym.hasAbstractFlag) ACC_ABSTRACT else 0,
+ if (classSym.isArtifact) ACC_SYNTHETIC else 0,
+ if (classSym.hasEnumFlag) enumFlags else 0
+ )
+ }
+
+ /**
* The member classes of a class symbol. Note that the result of this method depends on the
* current phase, for example, after lambdalift, all local classes become member of the enclosing
* class.
@@ -399,3 +438,16 @@ final class BCodeAsmCommon[G <: Global](val global: G) {
InlineInfo(traitSelfType, isEffectivelyFinal, methodInlineInfos, warning)
}
}
+
+object BCodeAsmCommon {
+ /**
+ * Valid flags for InnerClass attribute entry.
+ * See http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.6
+ */
+ val INNER_CLASSES_FLAGS = {
+ asm.Opcodes.ACC_PUBLIC | asm.Opcodes.ACC_PRIVATE | asm.Opcodes.ACC_PROTECTED |
+ asm.Opcodes.ACC_STATIC | asm.Opcodes.ACC_FINAL | asm.Opcodes.ACC_INTERFACE |
+ asm.Opcodes.ACC_ABSTRACT | asm.Opcodes.ACC_SYNTHETIC | asm.Opcodes.ACC_ANNOTATION |
+ asm.Opcodes.ACC_ENUM
+ }
+}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala
index a2fd22d24c..0f67852804 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala
@@ -90,7 +90,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
override def getCurrentCUnit(): CompilationUnit = { cunit }
- /* ---------------- helper utils for generating classes and fiels ---------------- */
+ /* ---------------- helper utils for generating classes and fields ---------------- */
def genPlainClass(cd: ClassDef) {
assert(cnode == null, "GenBCode detected nested methods.")
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala b/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala
index e61190bf3a..176292669c 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala
@@ -898,7 +898,7 @@ abstract class BTypes {
// the static flag in the InnerClass table has a special meaning, see InnerClass comment
i.flags & ~Opcodes.ACC_STATIC,
if (isStaticNestedClass) Opcodes.ACC_STATIC else 0
- ) & ClassBType.INNER_CLASSES_FLAGS
+ ) & BCodeAsmCommon.INNER_CLASSES_FLAGS
)
})
@@ -987,17 +987,6 @@ abstract class BTypes {
}
object ClassBType {
- /**
- * Valid flags for InnerClass attribute entry.
- * See http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.6
- */
- private val INNER_CLASSES_FLAGS = {
- asm.Opcodes.ACC_PUBLIC | asm.Opcodes.ACC_PRIVATE | asm.Opcodes.ACC_PROTECTED |
- asm.Opcodes.ACC_STATIC | asm.Opcodes.ACC_FINAL | asm.Opcodes.ACC_INTERFACE |
- asm.Opcodes.ACC_ABSTRACT | asm.Opcodes.ACC_SYNTHETIC | asm.Opcodes.ACC_ANNOTATION |
- asm.Opcodes.ACC_ENUM
- }
-
// Primitive classes have no super class. A ClassBType for those is only created when
// they are actually being compiled (e.g., when compiling scala/Boolean.scala).
private val hasNoSuper = Set(
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala b/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala
index fffb9286b8..d68c916f09 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala
@@ -213,35 +213,6 @@ class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
assert(!primitiveTypeMap.contains(sym) || isCompilingPrimitive, sym)
}
- /**
- * Reconstruct the classfile flags from a Java defined class symbol.
- *
- * The implementation of this method is slightly different that [[javaFlags]]. The javaFlags
- * method is primarily used to map Scala symbol flags to sensible classfile flags that are used
- * in the generated classfiles. For example, all classes emitted by the Scala compiler have
- * ACC_PUBLIC.
- *
- * When building a [[ClassBType]] from a Java class symbol, the flags in the type's `info` have
- * to correspond exactly to the flags in the classfile. For example, if the class is package
- * protected (i.e., it doesn't have the ACC_PUBLIC flag), this needs to be reflected in the
- * ClassBType. For example, the inliner needs the correct flags for access checks.
- *
- * Class flags are listed here:
- * https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-E.1
- */
- private def javaClassfileFlags(classSym: Symbol): Int = {
- assert(classSym.isJava, s"Expected Java class symbol, got ${classSym.fullName}")
- import asm.Opcodes._
- GenBCode.mkFlags(
- if (classSym.isPublic) ACC_PUBLIC else 0,
- if (classSym.isFinal) ACC_FINAL else 0,
- if (classSym.isInterface) ACC_INTERFACE else ACC_SUPER, // see the link above. javac does the same: ACC_SUPER for all classes, but not interfaces.
- if (classSym.hasAbstractFlag) ACC_ABSTRACT else 0,
- if (classSym.isArtifact) ACC_SYNTHETIC else 0,
- if (classSym.hasEnumFlag) ACC_ENUM else 0
- )
- }
-
private def setClassInfo(classSym: Symbol, classBType: ClassBType): ClassBType = {
val superClassSym = if (classSym.isImplClass) ObjectClass else classSym.superClass
assert(
@@ -322,7 +293,7 @@ class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
val javaCompatMembers = {
if (linkedClass != NoSymbol && isTopLevelModuleClass(linkedClass))
// phase travel to exitingPickler: this makes sure that memberClassesForInnerClassTable only sees member
- // classes, not local classes of the companion module (E in the exmaple) that were lifted by lambdalift.
+ // classes, not local classes of the companion module (E in the example) that were lifted by lambdalift.
exitingPickler(memberClassesForInnerClassTable(linkedClass))
else
Nil
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index 76af40b330..71686fd9d7 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -479,10 +479,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
val CLASS_CONSTRUCTOR_NAME = "<clinit>"
val INSTANCE_CONSTRUCTOR_NAME = "<init>"
- val INNER_CLASSES_FLAGS =
- (asm.Opcodes.ACC_PUBLIC | asm.Opcodes.ACC_PRIVATE | asm.Opcodes.ACC_PROTECTED |
- asm.Opcodes.ACC_STATIC | asm.Opcodes.ACC_INTERFACE | asm.Opcodes.ACC_ABSTRACT | asm.Opcodes.ACC_FINAL)
-
// -----------------------------------------------------------------------------------------
// factory methods
// -----------------------------------------------------------------------------------------
@@ -756,9 +752,9 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
val flagsWithFinal: Int = mkFlags(
// See comment in BTypes, when is a class marked static in the InnerClass table.
if (isOriginallyStaticOwner(innerSym.originalOwner)) asm.Opcodes.ACC_STATIC else 0,
- javaFlags(innerSym),
+ (if (innerSym.isJava) javaClassfileFlags(innerSym) else javaFlags(innerSym)) & ~asm.Opcodes.ACC_STATIC,
if(isDeprecated(innerSym)) asm.Opcodes.ACC_DEPRECATED else 0 // ASM pseudo-access flag
- ) & (INNER_CLASSES_FLAGS | asm.Opcodes.ACC_DEPRECATED)
+ ) & (BCodeAsmCommon.INNER_CLASSES_FLAGS | asm.Opcodes.ACC_DEPRECATED)
val flags = if (innerSym.isModuleClass) flagsWithFinal & ~asm.Opcodes.ACC_FINAL else flagsWithFinal // For SI-5676, object overriding.
val jname = javaName(innerSym) // never null
val oname = outerName(innerSym) // null when method-enclosed
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/ByteCodeRepository.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/ByteCodeRepository.scala
index 607b7145d6..dbf19744fa 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/opt/ByteCodeRepository.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/ByteCodeRepository.scala
@@ -127,7 +127,7 @@ class ByteCodeRepository(val classPath: ClassFileLookup[AbstractFile], val isJav
case Nil => Left(failedClasses)
}
- // In a MethodInsnNode, the `owner` field may be an array descriptor, for exmple when invoking `clone`. We don't have a method node to return in this case.
+ // In a MethodInsnNode, the `owner` field may be an array descriptor, for example when invoking `clone`. We don't have a method node to return in this case.
if (ownerInternalNameOrArrayDescriptor.charAt(0) == '[')
Left(MethodNotFound(name, descriptor, ownerInternalNameOrArrayDescriptor, Nil))
else
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
index 5f51a94673..bd5bab28b5 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
@@ -262,7 +262,7 @@ object LocalOptImpls {
* the same index, but distinct start / end ranges are different variables, they may have not the
* same type or name.
*/
- def removeUnusedLocalVariableNodes(method: MethodNode)(fistLocalIndex: Int = parametersSize(method), renumber: Int => Int = identity): Boolean = {
+ def removeUnusedLocalVariableNodes(method: MethodNode)(firstLocalIndex: Int = parametersSize(method), renumber: Int => Int = identity): Boolean = {
def variableIsUsed(start: AbstractInsnNode, end: LabelNode, varIndex: Int): Boolean = {
start != end && (start match {
case v: VarInsnNode if v.`var` == varIndex => true
@@ -276,7 +276,7 @@ object LocalOptImpls {
val local = localsIter.next()
val index = local.index
// parameters and `this` (the lowest indices, starting at 0) are never removed or renumbered
- if (index >= fistLocalIndex) {
+ if (index >= firstLocalIndex) {
if (!variableIsUsed(local.start, local.end, index)) localsIter.remove()
else if (renumber(index) != index) local.index = renumber(index)
}
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
index d34c14be0f..9708cba281 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
@@ -761,9 +761,13 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
val interfaces = interfacesOpt()
accept(LBRACE)
val buf = new ListBuffer[Tree]
+ var enumIsFinal = true
def parseEnumConsts() {
if (in.token != RBRACE && in.token != SEMI && in.token != EOF) {
- buf += enumConst(enumType)
+ val (const, hasClassBody) = enumConst(enumType)
+ buf += const
+ // if any of the enum constants has a class body, the enum class is not final (JLS 8.9.)
+ enumIsFinal &&= !hasClassBody
if (in.token == COMMA) {
in.nextToken()
parseEnumConsts()
@@ -793,15 +797,25 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
accept(RBRACE)
val superclazz =
AppliedTypeTree(javaLangDot(tpnme.Enum), List(enumType))
+ val finalFlag = if (enumIsFinal) Flags.FINAL else 0l
+ val abstractFlag = {
+ // javac adds `ACC_ABSTRACT` to enum classes with deferred members
+ val hasAbstractMember = body exists {
+ case d: DefDef => d.mods.isDeferred
+ case _ => false
+ }
+ if (hasAbstractMember) Flags.ABSTRACT else 0l
+ }
addCompanionObject(consts ::: statics ::: predefs, atPos(pos) {
- ClassDef(mods | Flags.ENUM, name, List(),
+ ClassDef(mods | Flags.ENUM | finalFlag | abstractFlag, name, List(),
makeTemplate(superclazz :: interfaces, body))
})
}
- def enumConst(enumType: Tree) = {
+ def enumConst(enumType: Tree): (ValDef, Boolean) = {
annotations()
- atPos(in.currentPos) {
+ var hasClassBody = false
+ val res = atPos(in.currentPos) {
val name = ident()
if (in.token == LPAREN) {
// skip arguments
@@ -809,12 +823,14 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
accept(RPAREN)
}
if (in.token == LBRACE) {
+ hasClassBody = true
// skip classbody
skipAhead()
accept(RBRACE)
}
ValDef(Modifiers(Flags.ENUM | Flags.STABLE | Flags.JAVA | Flags.STATIC), name.toTermName, enumType, blankExpr)
}
+ (res, hasClassBody)
}
def typeDecl(mods: Modifiers): List[Tree] = in.token match {
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 953e43eaca..d3cdf69d30 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -76,7 +76,7 @@ trait ScalaSettings extends AbsScalaSettings
val implicitConversions = Choice("implicitConversions", "Allow definition of implicit functions called views")
val higherKinds = Choice("higherKinds", "Allow higher-kinded types")
val existentials = Choice("existentials", "Existential types (besides wildcard types) can be written and inferred")
- val macros = Choice("experimental.macros", "Allow macro defintion (besides implementation and application)")
+ val macros = Choice("experimental.macros", "Allow macro definition (besides implementation and application)")
}
val language = {
val description = "Enable or disable language features"
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 518a402230..660028eab8 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -539,6 +539,8 @@ abstract class ClassfileParser {
devWarning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.")
case linked =>
if (!linked.isSealed)
+ // Marking the enum class SEALED | ABSTRACT enables exhaustiveness checking.
+ // This is a bit of a hack and requires excluding the ABSTRACT flag in the backend, see method javaClassfileFlags.
linked setFlag (SEALED | ABSTRACT)
linked addChild sym
}
diff --git a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
index 55ab73028e..5a7f6c52da 100644
--- a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
+++ b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
@@ -444,7 +444,7 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
def adaptAndPostErase(tree: Tree, pt: Type): (Boolean, Tree) = {
val (needsAdapt, adaptedTree) = adapt(tree, pt)
val trans = postErasure.newTransformer(unit)
- val postErasedTree = trans.atOwner(currentOwner)(trans.transform(adaptedTree)) // SI-8017 elimnates ErasedValueTypes
+ val postErasedTree = trans.atOwner(currentOwner)(trans.transform(adaptedTree)) // SI-8017 eliminates ErasedValueTypes
(needsAdapt, postErasedTree)
}
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
index 227c45b3a7..49a4990722 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
@@ -510,7 +510,7 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
def propForEqualsTo(c: Const): Prop = {observed(); symForEqualsTo.getOrElse(c, False)}
// [implementation NOTE: don't access until all potential equalities have been registered using registerEquality]p
- /** the information needed to construct the boolean proposition that encods the equality proposition (V = C)
+ /** the information needed to construct the boolean proposition that encodes the equality proposition (V = C)
*
* that models a type test pattern `_: C` or constant pattern `C`, where the type test gives rise to a TypeConst C,
* and the constant pattern yields a ValueConst C
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
index e1fe220556..e0fcc05de2 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
@@ -642,7 +642,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
}
// override def apply
- // debug.patmat("before fixerupper: "+ xTree)
+ // debug.patmat("before fixerUpper: "+ xTree)
// currentRun.trackerFactory.snapshot()
// debug.patmat("after fixerupper")
// currentRun.trackerFactory.snapshot()
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 7edd36dc22..17cf02cce6 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -153,7 +153,7 @@ import scala.language.implicitConversions
*
* - The fact that `tail` works at all is of interest. In the definition of
* `fibs` we have an initial `(0, 1, Stream(...))` so `tail` is deterministic.
- * If we deinfed `fibs` such that only `0` were concretely known then the act
+ * If we defined `fibs` such that only `0` were concretely known then the act
* of determining `tail` would require the evaluation of `tail` which would
* cause an infinite recursion and stack overflow. If we define a definition
* where the tail is not initially computable then we're going to have an
diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala
index 47a623a616..46d5d0c69c 100644
--- a/src/library/scala/collection/immutable/Vector.scala
+++ b/src/library/scala/collection/immutable/Vector.scala
@@ -132,19 +132,25 @@ override def companion: GenericCompanion[Vector] = Vector
throw new IndexOutOfBoundsException(index.toString)
}
-
+ // If we have a default builder, there are faster ways to perform some operations
+ @inline private[this] def isDefaultCBF[A, B, That](bf: CanBuildFrom[Vector[A], B, That]): Boolean =
+ (bf eq IndexedSeq.ReusableCBF) || (bf eq collection.immutable.Seq.ReusableCBF) || (bf eq collection.Seq.ReusableCBF)
+
// SeqLike api
override def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That =
- if (bf eq IndexedSeq.ReusableCBF) updateAt(index, elem).asInstanceOf[That] // just ignore bf
+ if (isDefaultCBF[A, B, That](bf))
+ updateAt(index, elem).asInstanceOf[That] // ignore bf--it will just give a Vector, and slowly
else super.updated(index, elem)(bf)
override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That =
- if (bf eq IndexedSeq.ReusableCBF) appendFront(elem).asInstanceOf[That] // just ignore bf
+ if (isDefaultCBF[A, B, That](bf))
+ appendFront(elem).asInstanceOf[That] // ignore bf--it will just give a Vector, and slowly
else super.+:(elem)(bf)
override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That =
- if (bf eq IndexedSeq.ReusableCBF) appendBack(elem).asInstanceOf[That] // just ignore bf
+ if (isDefaultCBF(bf))
+ appendBack(elem).asInstanceOf[That] // ignore bf--it will just give a Vector, and slowly
else super.:+(elem)(bf)
override def take(n: Int): Vector[A] = {
@@ -211,7 +217,8 @@ override def companion: GenericCompanion[Vector] = Vector
// concat (suboptimal but avoids worst performance gotchas)
override def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Vector[A], B, That]): That = {
- if (bf eq IndexedSeq.ReusableCBF) {
+ if (isDefaultCBF(bf)) {
+ // We are sure we will create a Vector, so let's do it efficiently
import Vector.{Log2ConcatFaster, TinyAppendFaster}
if (that.isEmpty) this.asInstanceOf[That]
else {
diff --git a/src/reflect/scala/reflect/internal/ClassfileConstants.scala b/src/reflect/scala/reflect/internal/ClassfileConstants.scala
index e0a6757d34..53241fb15b 100644
--- a/src/reflect/scala/reflect/internal/ClassfileConstants.scala
+++ b/src/reflect/scala/reflect/internal/ClassfileConstants.scala
@@ -344,10 +344,12 @@ object ClassfileConstants {
case JAVA_ACC_STATIC => STATIC
case JAVA_ACC_ABSTRACT => if (isAnnotation) 0L else if (isClass) ABSTRACT else DEFERRED
case JAVA_ACC_INTERFACE => if (isAnnotation) 0L else TRAIT | INTERFACE | ABSTRACT
+ case JAVA_ACC_ENUM => ENUM
case _ => 0L
}
- private def translateFlags(jflags: Int, baseFlags: Long, isAnnotation: Boolean, isClass: Boolean): Long = {
- def translateFlag0(jflags: Int): Long = translateFlag(jflags, isAnnotation, isClass)
+ private def translateFlags(jflags: Int, baseFlags: Long, isClass: Boolean): Long = {
+ val isAnnot = isAnnotation(jflags)
+ def translateFlag0(jflags: Int): Long = translateFlag(jflags, isAnnot, isClass)
var res: Long = JAVA | baseFlags
/* fast, elegant, maintainable, pick any two... */
res |= translateFlag0(jflags & JAVA_ACC_PRIVATE)
@@ -357,17 +359,18 @@ object ClassfileConstants {
res |= translateFlag0(jflags & JAVA_ACC_STATIC)
res |= translateFlag0(jflags & JAVA_ACC_ABSTRACT)
res |= translateFlag0(jflags & JAVA_ACC_INTERFACE)
+ res |= translateFlag0(jflags & JAVA_ACC_ENUM)
res
}
def classFlags(jflags: Int): Long = {
- translateFlags(jflags, 0, isAnnotation(jflags), isClass = true)
+ translateFlags(jflags, 0, isClass = true)
}
def fieldFlags(jflags: Int): Long = {
- translateFlags(jflags, if ((jflags & JAVA_ACC_FINAL) == 0) MUTABLE else 0 , isAnnotation(jflags), isClass = false)
+ translateFlags(jflags, if ((jflags & JAVA_ACC_FINAL) == 0) MUTABLE else 0 , isClass = false)
}
def methodFlags(jflags: Int): Long = {
- translateFlags(jflags, if ((jflags & JAVA_ACC_BRIDGE) != 0) BRIDGE | ARTIFACT else 0, isAnnotation(jflags), isClass = false)
+ translateFlags(jflags, if ((jflags & JAVA_ACC_BRIDGE) != 0) BRIDGE | ARTIFACT else 0, isClass = false)
}
}
object FlagTranslation extends FlagTranslation { }
diff --git a/src/reflect/scala/reflect/internal/ReificationSupport.scala b/src/reflect/scala/reflect/internal/ReificationSupport.scala
index eddfec82e7..d393a841b7 100644
--- a/src/reflect/scala/reflect/internal/ReificationSupport.scala
+++ b/src/reflect/scala/reflect/internal/ReificationSupport.scala
@@ -802,7 +802,7 @@ trait ReificationSupport { self: SymbolTable =>
require(enums.nonEmpty, "enumerators can't be empty")
enums.head match {
case SyntacticValFrom(_, _) =>
- case t => throw new IllegalArgumentException(s"$t is not a valid fist enumerator of for loop")
+ case t => throw new IllegalArgumentException(s"$t is not a valid first enumerator of for loop")
}
enums.tail.foreach {
case SyntacticValEq(_, _) | SyntacticValFrom(_, _) | SyntacticFilter(_) =>
diff --git a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
index c705ca7069..15a87200f1 100644
--- a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
+++ b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
@@ -561,7 +561,7 @@ private[internal] trait TypeMaps {
| tparams ${rhsSym.typeParams map own_s mkString ", "}
|"""
- if (argIndex < 0)
+ if (!rhsArgs.isDefinedAt(argIndex))
abort(s"Something is wrong: cannot find $lhs in applied type $rhs\n" + explain)
else {
val targ = rhsArgs(argIndex)
diff --git a/src/repl/scala/tools/nsc/interpreter/session/FileBackedHistory.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/FileBackedHistory.scala
index dddfb1b8f6..b6c9792ec0 100644
--- a/src/repl/scala/tools/nsc/interpreter/session/FileBackedHistory.scala
+++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/FileBackedHistory.scala
@@ -1,20 +1,22 @@
/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
+ * Copyright 2005-2015 LAMP/EPFL
* @author Paul Phillips
*/
-package scala.tools.nsc
-package interpreter
-package session
+package scala.tools.nsc.interpreter.jline
-import scala.tools.nsc.io._
-import FileBackedHistory._
+import _root_.jline.console.history.PersistentHistory
+
+
+import scala.tools.nsc.interpreter
+import scala.tools.nsc.io.{File, Path}
/** TODO: file locking.
- */
-trait FileBackedHistory extends JLineHistory with JPersistentHistory {
+ */
+trait FileBackedHistory extends JLineHistory with PersistentHistory {
def maxSize: Int
- protected lazy val historyFile: File = defaultFile
+
+ protected lazy val historyFile: File = FileBackedHistory.defaultFile
private var isPersistent = true
locally {
@@ -27,6 +29,7 @@ trait FileBackedHistory extends JLineHistory with JPersistentHistory {
try op
finally isPersistent = saved
}
+
def addLineToFile(item: CharSequence): Unit = {
if (isPersistent)
append(item + "\n")
@@ -37,6 +40,7 @@ trait FileBackedHistory extends JLineHistory with JPersistentHistory {
val lines = asStrings map (_ + "\n")
historyFile.writeAll(lines: _*)
}
+
/** Append one or more lines to the history file. */
protected def append(lines: String*): Unit = {
historyFile.appendAll(lines: _*)
@@ -54,31 +58,36 @@ trait FileBackedHistory extends JLineHistory with JPersistentHistory {
// than abandon hope we'll try to read it as ISO-8859-1
case _: Exception =>
try historyFile.lines("ISO-8859-1").toIndexedSeq
- catch { case _: Exception => Vector() }
+ catch {
+ case _: Exception => Vector()
+ }
}
}
- repldbg("Loading " + lines.size + " into history.")
+ interpreter.repldbg("Loading " + lines.size + " into history.")
// avoid writing to the history file
withoutSaving(lines takeRight maxSize foreach add)
// truncate the history file if it's too big.
if (lines.size > maxSize) {
- repldbg("File exceeds maximum size: truncating to " + maxSize + " entries.")
+ interpreter.repldbg("File exceeds maximum size: truncating to " + maxSize + " entries.")
sync()
}
moveToEnd()
}
def flush(): Unit = ()
+
def purge(): Unit = historyFile.truncate()
}
object FileBackedHistory {
// val ContinuationChar = '\003'
// val ContinuationNL: String = Array('\003', '\n').mkString
- import Properties.userHome
+
+ import scala.tools.nsc.Properties.userHome
def defaultFileName = ".scala_history"
+
def defaultFile: File = File(Path(userHome) / defaultFileName)
}
diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineDelimiter.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineDelimiter.scala
new file mode 100644
index 0000000000..c18a9809a0
--- /dev/null
+++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineDelimiter.scala
@@ -0,0 +1,25 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2013 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc.interpreter.jline
+
+import scala.tools.nsc.interpreter
+
+import _root_.jline.console.completer.ArgumentCompleter.{ ArgumentDelimiter, ArgumentList }
+
+// implements a jline interface
+class JLineDelimiter extends ArgumentDelimiter {
+ def toJLine(args: List[String], cursor: Int) = args match {
+ case Nil => new ArgumentList(new Array[String](0), 0, 0, cursor)
+ case xs => new ArgumentList(xs.toArray, xs.size - 1, xs.last.length, cursor)
+ }
+
+ def delimit(buffer: CharSequence, cursor: Int) = {
+ val p = interpreter.Parsed(buffer.toString, cursor)
+ toJLine(p.args, cursor)
+ }
+
+ def isDelimiter(buffer: CharSequence, cursor: Int) = interpreter.Parsed(buffer.toString, cursor).isDelimiter
+}
diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineHistory.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineHistory.scala
new file mode 100644
index 0000000000..1f6a1f7022
--- /dev/null
+++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineHistory.scala
@@ -0,0 +1,77 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2013 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc.interpreter.jline
+
+import java.util.{Iterator => JIterator, ListIterator => JListIterator}
+
+import _root_.jline.{console => jconsole}
+import jconsole.history.History.{Entry => JEntry}
+import jconsole.history.{History => JHistory}
+
+import scala.tools.nsc.interpreter
+import scala.tools.nsc.interpreter.session.{History, SimpleHistory}
+
+
+/** A straight scalification of the jline interface which mixes
+ * in the sparse jline-independent one too.
+ */
+trait JLineHistory extends JHistory with History {
+ def size: Int
+ def isEmpty: Boolean
+ def index: Int
+ def clear(): Unit
+ def get(index: Int): CharSequence
+ def add(line: CharSequence): Unit
+ def replace(item: CharSequence): Unit
+
+ def entries(index: Int): JListIterator[JEntry]
+ def entries(): JListIterator[JEntry]
+ def iterator: JIterator[JEntry]
+
+ def current(): CharSequence
+ def previous(): Boolean
+ def next(): Boolean
+ def moveToFirst(): Boolean
+ def moveToLast(): Boolean
+ def moveTo(index: Int): Boolean
+ def moveToEnd(): Unit
+
+ override def historicize(text: String): Boolean = {
+ text.lines foreach add
+ moveToEnd()
+ true
+ }
+}
+
+object JLineHistory {
+ class JLineFileHistory extends SimpleHistory with FileBackedHistory {
+ override def add(item: CharSequence): Unit = {
+ if (!isEmpty && last == item)
+ interpreter.repldbg("Ignoring duplicate entry '" + item + "'")
+ else {
+ super.add(item)
+ addLineToFile(item)
+ }
+ }
+ override def toString = "History(size = " + size + ", index = " + index + ")"
+
+ import scala.collection.JavaConverters._
+
+ override def asStrings(from: Int, to: Int): List[String] =
+ entries(from).asScala.take(to - from).map(_.value.toString).toList
+
+ case class Entry(index: Int, value: CharSequence) extends JEntry {
+ override def toString = value.toString
+ }
+
+ private def toEntries(): Seq[JEntry] = buf.zipWithIndex map { case (x, i) => Entry(i, x)}
+ def entries(idx: Int): JListIterator[JEntry] = toEntries().asJava.listIterator(idx)
+ def entries(): JListIterator[JEntry] = toEntries().asJava.listIterator()
+ def iterator: JIterator[JEntry] = toEntries().iterator.asJava
+ }
+
+ def apply(): History = try new JLineFileHistory catch { case x: Exception => new SimpleHistory() }
+}
diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala
new file mode 100644
index 0000000000..f0fce13fe8
--- /dev/null
+++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala
@@ -0,0 +1,143 @@
+/** NSC -- new Scala compiler
+ *
+ * Copyright 2005-2015 LAMP/EPFL
+ * @author Stepan Koltsov
+ * @author Adriaan Moors
+ */
+
+package scala.tools.nsc.interpreter.jline
+
+import java.util.{Collection => JCollection, List => JList}
+
+import _root_.jline.{console => jconsole}
+import jconsole.completer.{Completer, ArgumentCompleter}
+import jconsole.history.{History => JHistory}
+
+
+import scala.tools.nsc.interpreter
+import scala.tools.nsc.interpreter.Completion
+import scala.tools.nsc.interpreter.Completion.Candidates
+import scala.tools.nsc.interpreter.session.History
+
+/**
+ * Reads from the console using JLine.
+ *
+ * Eagerly instantiates all relevant JLine classes, so that we can detect linkage errors on `new JLineReader` and retry.
+ */
+class InteractiveReader(completer: () => Completion) extends interpreter.InteractiveReader {
+ val interactive = true
+
+ val history: History = new JLineHistory.JLineFileHistory()
+
+ private val consoleReader = {
+ val reader = new JLineConsoleReader()
+
+ reader setPaginationEnabled interpreter.`package`.isPaged
+
+ // ASAP
+ reader setExpandEvents false
+
+ reader setHistory history.asInstanceOf[JHistory]
+
+ reader
+ }
+
+ private[this] var _completion: Completion = interpreter.NoCompletion
+ def completion: Completion = _completion
+
+ override def postInit() = {
+ _completion = completer()
+
+ consoleReader.initCompletion(completion)
+ }
+
+ def reset() = consoleReader.getTerminal().reset()
+ def redrawLine() = consoleReader.redrawLineAndFlush()
+ def readOneLine(prompt: String) = consoleReader.readLine(prompt)
+ def readOneKey(prompt: String) = consoleReader.readOneKey(prompt)
+}
+
+// implements a jline interface
+private class JLineConsoleReader extends jconsole.ConsoleReader with interpreter.VariColumnTabulator {
+ val isAcross = interpreter.`package`.isAcross
+ val marginSize = 3
+
+ def width = getTerminal.getWidth()
+ def height = getTerminal.getHeight()
+
+ private def morePrompt = "--More--"
+
+ private def emulateMore(): Int = {
+ val key = readOneKey(morePrompt)
+ try key match {
+ case '\r' | '\n' => 1
+ case 'q' => -1
+ case _ => height - 1
+ }
+ finally {
+ eraseLine()
+ // TODO: still not quite managing to erase --More-- and get
+ // back to a scala prompt without another keypress.
+ if (key == 'q') {
+ putString(getPrompt())
+ redrawLine()
+ flush()
+ }
+ }
+ }
+
+ override def printColumns(items: JCollection[_ <: CharSequence]): Unit = {
+ import scala.tools.nsc.interpreter.javaCharSeqCollectionToScala
+ printColumns_(items: List[String])
+ }
+
+ private def printColumns_(items: List[String]): Unit = if (items exists (_ != "")) {
+ val grouped = tabulate(items)
+ var linesLeft = if (isPaginationEnabled()) height - 1 else Int.MaxValue
+ grouped foreach { xs =>
+ println(xs.mkString)
+ linesLeft -= 1
+ if (linesLeft <= 0) {
+ linesLeft = emulateMore()
+ if (linesLeft < 0)
+ return
+ }
+ }
+ }
+
+ def readOneKey(prompt: String) = {
+ this.print(prompt)
+ this.flush()
+ this.readCharacter()
+ }
+
+ def eraseLine() = resetPromptLine("", "", 0)
+
+ def redrawLineAndFlush(): Unit = {
+ flush(); drawLine(); flush()
+ }
+
+ // A hook for running code after the repl is done initializing.
+ def initCompletion(completion: Completion): Unit = {
+ this setBellEnabled false
+
+ if (completion ne interpreter.NoCompletion) {
+ val jlineCompleter = new ArgumentCompleter(new JLineDelimiter,
+ new Completer {
+ val tc = completion.completer()
+ def complete(_buf: String, cursor: Int, candidates: JList[CharSequence]): Int = {
+ val buf = if (_buf == null) "" else _buf
+ val Candidates(newCursor, newCandidates) = tc.complete(buf, cursor)
+ newCandidates foreach (candidates add _)
+ newCursor
+ }
+ }
+ )
+
+ jlineCompleter setStrict false
+
+ this addCompleter jlineCompleter
+ this setAutoprintThreshold 400 // max completion candidates without warning
+ }
+ }
+}
diff --git a/src/repl/scala/tools/nsc/interpreter/Delimited.scala b/src/repl/scala/tools/nsc/interpreter/Delimited.scala
deleted file mode 100644
index b7f06f1d0a..0000000000
--- a/src/repl/scala/tools/nsc/interpreter/Delimited.scala
+++ /dev/null
@@ -1,41 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package interpreter
-
-import jline.console.completer.ArgumentCompleter.{ ArgumentDelimiter, ArgumentList }
-
-class JLineDelimiter extends ArgumentDelimiter {
- def toJLine(args: List[String], cursor: Int) = args match {
- case Nil => new ArgumentList(new Array[String](0), 0, 0, cursor)
- case xs => new ArgumentList(xs.toArray, xs.size - 1, xs.last.length, cursor)
- }
-
- def delimit(buffer: CharSequence, cursor: Int) = {
- val p = Parsed(buffer.toString, cursor)
- toJLine(p.args, cursor)
- }
- def isDelimiter(buffer: CharSequence, cursor: Int) = Parsed(buffer.toString, cursor).isDelimiter
-}
-
-trait Delimited {
- self: Parsed =>
-
- def delimited: Char => Boolean
- def escapeChars: List[Char] = List('\\')
-
- /** Break String into args based on delimiting function.
- */
- protected def toArgs(s: String): List[String] =
- if (s == "") Nil
- else (s indexWhere isDelimiterChar) match {
- case -1 => List(s)
- case idx => (s take idx) :: toArgs(s drop (idx + 1))
- }
-
- def isDelimiterChar(ch: Char) = delimited(ch)
- def isEscapeChar(ch: Char): Boolean = escapeChars contains ch
-}
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index bf4d107215..525609171e 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -26,6 +26,8 @@ import scala.concurrent.{ ExecutionContext, Await, Future, future }
import ExecutionContext.Implicits._
import java.io.{ BufferedReader, FileReader }
+import scala.util.{Try, Success, Failure}
+
/** The Scala interactive shell. It provides a read-eval-print loop
* around the Interpreter class.
* After instantiation, clients should call the main() method.
@@ -494,10 +496,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
val errless = intp compileSources new BatchSourceFile("<pastie>", s"object pastel {\n$code\n}")
if (errless) echo("The compiler reports no errors.")
}
- def historicize(text: String) = history match {
- case jlh: JLineHistory => text.lines foreach jlh.add ; jlh.moveToEnd() ; true
- case _ => false
- }
+
def edit(text: String): Result = editor match {
case Some(ed) =>
val tmp = File.makeTemp()
@@ -513,7 +512,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
val res = intp interpret edited
if (res == IR.Incomplete) diagnose(edited)
else {
- historicize(edited)
+ history.historicize(edited)
Result(lineToRecord = Some(edited), keepRunning = true)
}
case None => echo("Can't read edited text. Did you delete it?")
@@ -524,7 +523,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
tmp.delete()
}
case None =>
- if (historicize(text)) echo("Placing text in recent history.")
+ if (history.historicize(text)) echo("Placing text in recent history.")
else echo(f"No EDITOR defined and you can't change history, echoing your text:%n$text")
}
@@ -556,10 +555,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
import scala.collection.JavaConverters._
val index = (start - 1) max 0
- val text = history match {
- case jlh: JLineHistory => jlh.entries(index).asScala.take(len) map (_.value) mkString "\n"
- case _ => history.asStrings.slice(index, index + len) mkString "\n"
- }
+ val text = history.asStrings(index, index + len) mkString "\n"
edit(text)
} catch {
case _: NumberFormatException => echo(s"Bad range '$what'")
@@ -858,16 +854,36 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
* with SimpleReader.
*/
def chooseReader(settings: Settings): InteractiveReader = {
- if (settings.Xnojline || Properties.isEmacsShell)
- SimpleReader()
- else try new JLineReader(
- if (settings.noCompletion) NoCompletion
- else new JLineCompletion(intp)
- )
- catch {
- case ex @ (_: Exception | _: NoClassDefFoundError) =>
- echo(f"Failed to created JLineReader: ${ex}%nFalling back to SimpleReader.")
- SimpleReader()
+ if (settings.Xnojline || Properties.isEmacsShell) SimpleReader()
+ else {
+ type Completer = () => Completion
+ type ReaderMaker = Completer => InteractiveReader
+
+ def instantiate(className: String): ReaderMaker = completer => {
+ if (settings.debug) Console.println(s"Trying to instantiate a InteractiveReader from $className")
+ Class.forName(className).getConstructor(classOf[Completer]).
+ newInstance(completer).
+ asInstanceOf[InteractiveReader]
+ }
+
+ def mkReader(maker: ReaderMaker) =
+ if (settings.noCompletion) maker(() => NoCompletion)
+ else maker(() => new JLineCompletion(intp)) // JLineCompletion is a misnomer -- it's not tied to jline
+
+ def internalClass(kind: String) = s"scala.tools.nsc.interpreter.$kind.InteractiveReader"
+ val readerClasses = sys.props.get("scala.repl.reader").toStream ++ Stream(internalClass("jline"), internalClass("jline_embedded"))
+ val readers = readerClasses map (cls => Try { mkReader(instantiate(cls)) })
+
+ val reader = (readers collect { case Success(reader) => reader } headOption) getOrElse SimpleReader()
+
+ if (settings.debug) {
+ val readerDiags = (readerClasses, readers).zipped map {
+ case (cls, Failure(e)) => s" - $cls --> " + e.getStackTrace.mkString(e.toString+"\n\t", "\n\t","\n")
+ case (cls, Success(_)) => s" - $cls OK"
+ }
+ Console.println(s"All InteractiveReaders tried: ${readerDiags.mkString("\n","\n","\n")}")
+ }
+ reader
}
}
@@ -888,10 +904,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
asyncMessage(power.banner)
}
// SI-7418 Now, and only now, can we enable TAB completion.
- in match {
- case x: JLineReader => x.consoleReader.postInit
- case _ =>
- }
+ in.postInit()
}
// start an interpreter with the given settings
diff --git a/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala
index ed69d449cb..71753a3e39 100644
--- a/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala
+++ b/src/repl/scala/tools/nsc/interpreter/InteractiveReader.scala
@@ -13,6 +13,8 @@ import Properties.isMac
/** Reads lines from an input stream */
trait InteractiveReader {
+ def postInit(): Unit = {}
+
val interactive: Boolean
def reset(): Unit
diff --git a/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala b/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala
index c1122d4223..d878988e26 100644
--- a/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala
+++ b/src/repl/scala/tools/nsc/interpreter/JLineCompletion.scala
@@ -12,6 +12,7 @@ import scala.reflect.internal.util.StringOps.longestCommonPrefix
// REPL completor - queries supplied interpreter for valid
// completions based on current contents of buffer.
+// TODO: change class name to reflect it's not specific to jline (nor does it depend on it)
class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput {
val global: intp.global.type = intp.global
import global._
diff --git a/src/repl/scala/tools/nsc/interpreter/JLineReader.scala b/src/repl/scala/tools/nsc/interpreter/JLineReader.scala
deleted file mode 100644
index b6e834a1ed..0000000000
--- a/src/repl/scala/tools/nsc/interpreter/JLineReader.scala
+++ /dev/null
@@ -1,75 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Stepan Koltsov
- */
-
-package scala.tools.nsc
-package interpreter
-
-import jline.console.ConsoleReader
-import jline.console.completer._
-import session._
-import Completion._
-
-/**
- * Reads from the console using JLine.
- */
-class JLineReader(_completion: => Completion) extends InteractiveReader {
- val interactive = true
- val consoleReader = new JLineConsoleReader()
-
- lazy val completion = _completion
- lazy val history: JLineHistory = JLineHistory()
-
- private def term = consoleReader.getTerminal()
- def reset() = term.reset()
-
- def scalaToJline(tc: ScalaCompleter): Completer = new Completer {
- def complete(_buf: String, cursor: Int, candidates: JList[CharSequence]): Int = {
- val buf = if (_buf == null) "" else _buf
- val Candidates(newCursor, newCandidates) = tc.complete(buf, cursor)
- newCandidates foreach (candidates add _)
- newCursor
- }
- }
-
- class JLineConsoleReader extends ConsoleReader with ConsoleReaderHelper with VariColumnTabulator {
- val isAcross = interpreter.`package`.isAcross
-
- this setPaginationEnabled interpreter.`package`.isPaged
-
- // ASAP
- this setExpandEvents false
-
- // working around protected/trait/java insufficiencies.
- def goBack(num: Int): Unit = back(num)
- if ((history: History) ne NoHistory)
- this setHistory history
-
- def readOneKey(prompt: String) = {
- this.print(prompt)
- this.flush()
- this.readCharacter()
- }
- def eraseLine() = consoleReader.resetPromptLine("", "", 0)
- def redrawLineAndFlush(): Unit = { flush() ; drawLine() ; flush() }
-
- // A hook for running code after the repl is done initializing.
- lazy val postInit: Unit = {
- this setBellEnabled false
-
- if (completion ne NoCompletion) {
- val argCompletor: ArgumentCompleter =
- new ArgumentCompleter(new JLineDelimiter, scalaToJline(completion.completer()))
- argCompletor setStrict false
-
- this addCompleter argCompletor
- this setAutoprintThreshold 400 // max completion candidates without warning
- }
- }
- }
-
- def redrawLine() = consoleReader.redrawLineAndFlush()
- def readOneLine(prompt: String) = consoleReader readLine prompt
- def readOneKey(prompt: String) = consoleReader readOneKey prompt
-}
diff --git a/src/repl/scala/tools/nsc/interpreter/Parsed.scala b/src/repl/scala/tools/nsc/interpreter/Parsed.scala
index 672a6fd28f..5e58d3a2c4 100644
--- a/src/repl/scala/tools/nsc/interpreter/Parsed.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Parsed.scala
@@ -8,6 +8,25 @@ package interpreter
import util.returning
+trait Delimited {
+ self: Parsed =>
+
+ def delimited: Char => Boolean
+ def escapeChars: List[Char] = List('\\')
+
+ /** Break String into args based on delimiting function.
+ */
+ protected def toArgs(s: String): List[String] =
+ if (s == "") Nil
+ else (s indexWhere isDelimiterChar) match {
+ case -1 => List(s)
+ case idx => (s take idx) :: toArgs(s drop (idx + 1))
+ }
+
+ def isDelimiterChar(ch: Char) = delimited(ch)
+ def isEscapeChar(ch: Char): Boolean = escapeChars contains ch
+}
+
/** One instance of a command buffer.
*/
class Parsed private (
diff --git a/src/repl/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala b/src/repl/scala/tools/nsc/interpreter/Tabulators.scala
index a8d537e314..75bec168eb 100644
--- a/src/repl/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala
+++ b/src/repl/scala/tools/nsc/interpreter/Tabulators.scala
@@ -3,60 +3,7 @@
* @author Paul Phillips
*/
-package scala.tools.nsc
-package interpreter
-
-import jline.console.{ ConsoleReader, CursorBuffer }
-
-trait ConsoleReaderHelper { _: ConsoleReader with Tabulator =>
- def isAcross: Boolean
-
- def terminal = getTerminal()
- def width = terminal.getWidth()
- def height = terminal.getHeight()
-
- def readOneKey(prompt: String): Int
- def eraseLine(): Unit
-
- val marginSize = 3
-
- private def morePrompt = "--More--"
- private def emulateMore(): Int = {
- val key = readOneKey(morePrompt)
- try key match {
- case '\r' | '\n' => 1
- case 'q' => -1
- case _ => height - 1
- }
- finally {
- eraseLine()
- // TODO: still not quite managing to erase --More-- and get
- // back to a scala prompt without another keypress.
- if (key == 'q') {
- putString(getPrompt())
- redrawLine()
- flush()
- }
- }
- }
-
- override def printColumns(items: JCollection[_ <: CharSequence]): Unit =
- printColumns_(items: List[String])
-
- private def printColumns_(items: List[String]): Unit = if (items exists (_ != "")) {
- val grouped = tabulate(items)
- var linesLeft = if (isPaginationEnabled()) height - 1 else Int.MaxValue
- grouped foreach { xs =>
- println(xs.mkString)
- linesLeft -= 1
- if (linesLeft <= 0) {
- linesLeft = emulateMore()
- if (linesLeft < 0)
- return
- }
- }
- }
-}
+package scala.tools.nsc.interpreter
trait Tabulator {
def isAcross: Boolean
@@ -72,7 +19,7 @@ trait Tabulator {
)
protected def columnize(ss: Seq[String]): Seq[Seq[String]] = ss map (s => Seq(s))
protected def printMultiLineColumns(items: Seq[String]): Seq[Seq[String]] = {
- import SimpleMath._
+ import scala.tools.nsc.interpreter.SimpleMath._
val longest = (items map (_.length)).max
val columnWidth = longest + marginSize
val maxcols = (
@@ -101,7 +48,7 @@ trait Tabulator {
/** Adjust the column width and number of columns to minimize the row count. */
trait VariColumnTabulator extends Tabulator {
override protected def printMultiLineColumns(items: Seq[String]): Seq[Seq[String]] = {
- import SimpleMath._
+ import scala.tools.nsc.interpreter.SimpleMath._
val longest = (items map (_.length)).max
val shortest = (items map (_.length)).min
val fattest = longest + marginSize
diff --git a/src/repl/scala/tools/nsc/interpreter/session/History.scala b/src/repl/scala/tools/nsc/interpreter/session/History.scala
index 794d41adc7..2028a13dfd 100644
--- a/src/repl/scala/tools/nsc/interpreter/session/History.scala
+++ b/src/repl/scala/tools/nsc/interpreter/session/History.scala
@@ -11,7 +11,10 @@ package session
* reference to the jline classes. Very sparse right now.
*/
trait History {
+ def historicize(text: String): Boolean = false
+
def asStrings: List[String]
+ def asStrings(from: Int, to: Int): List[String] = asStrings.slice(from, to)
def index: Int
def size: Int
}
diff --git a/src/repl/scala/tools/nsc/interpreter/session/JLineHistory.scala b/src/repl/scala/tools/nsc/interpreter/session/JLineHistory.scala
deleted file mode 100644
index 18e0ee7c85..0000000000
--- a/src/repl/scala/tools/nsc/interpreter/session/JLineHistory.scala
+++ /dev/null
@@ -1,49 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package interpreter
-package session
-
-/** A straight scalification of the jline interface which mixes
- * in the sparse jline-independent one too.
- */
-trait JLineHistory extends JHistory with History {
- def size: Int
- def isEmpty: Boolean
- def index: Int
- def clear(): Unit
- def get(index: Int): CharSequence
- def add(line: CharSequence): Unit
- def replace(item: CharSequence): Unit
-
- def entries(index: Int): JListIterator[JEntry]
- def entries(): JListIterator[JEntry]
- def iterator: JIterator[JEntry]
-
- def current(): CharSequence
- def previous(): Boolean
- def next(): Boolean
- def moveToFirst(): Boolean
- def moveToLast(): Boolean
- def moveTo(index: Int): Boolean
- def moveToEnd(): Unit
-}
-
-object JLineHistory {
- class JLineFileHistory extends SimpleHistory with FileBackedHistory {
- override def add(item: CharSequence): Unit = {
- if (!isEmpty && last == item)
- repldbg("Ignoring duplicate entry '" + item + "'")
- else {
- super.add(item)
- addLineToFile(item)
- }
- }
- override def toString = "History(size = " + size + ", index = " + index + ")"
- }
-
- def apply(): JLineHistory = try new JLineFileHistory catch { case x: Exception => new SimpleHistory() }
-}
diff --git a/src/repl/scala/tools/nsc/interpreter/session/SimpleHistory.scala b/src/repl/scala/tools/nsc/interpreter/session/SimpleHistory.scala
index 7c49b91296..504d0d30ee 100644
--- a/src/repl/scala/tools/nsc/interpreter/session/SimpleHistory.scala
+++ b/src/repl/scala/tools/nsc/interpreter/session/SimpleHistory.scala
@@ -10,10 +10,9 @@ package session
import scala.collection.mutable.{ Buffer, ListBuffer }
import scala.collection.JavaConverters._
-class SimpleHistory extends JLineHistory {
+class SimpleHistory extends History {
private var _index: Int = 0
- private val buf: Buffer[String] = new ListBuffer[String]
- private def toEntries(): Seq[JEntry] = buf.zipWithIndex map { case (x, i) => Entry(i, x) }
+ protected val buf: Buffer[String] = new ListBuffer[String]
private def setTo(num: Int) = { _index = num ; true }
private def minusOne = { _index -= 1 ; true }
private def plusOne = { _index += 1 ; true }
@@ -25,10 +24,6 @@ class SimpleHistory extends JLineHistory {
""
}
- case class Entry(index: Int, value: CharSequence) extends JEntry {
- override def toString = value
- }
-
def maxSize: Int = 2500
def last = if (isEmpty) fail("last") else buf.last
@@ -42,9 +37,6 @@ class SimpleHistory extends JLineHistory {
buf trimEnd 1
add(item)
}
- def entries(idx: Int): JListIterator[JEntry] = toEntries().asJava.listIterator(idx)
- def entries(): JListIterator[JEntry] = toEntries().asJava.listIterator()
- def iterator: JIterator[JEntry] = toEntries().iterator.asJava
def remove(idx: Int): CharSequence = buf remove idx
def removeFirst(): CharSequence = buf remove 0
diff --git a/src/repl/scala/tools/nsc/interpreter/session/package.scala b/src/repl/scala/tools/nsc/interpreter/session/package.scala
index a3d7312c98..06e7f6207b 100644
--- a/src/repl/scala/tools/nsc/interpreter/session/package.scala
+++ b/src/repl/scala/tools/nsc/interpreter/session/package.scala
@@ -14,10 +14,5 @@ package object session {
type JIterator[T] = java.util.Iterator[T]
type JListIterator[T] = java.util.ListIterator[T]
- type JEntry = jline.console.history.History.Entry
- type JHistory = jline.console.history.History
- type JMemoryHistory = jline.console.history.MemoryHistory
- type JPersistentHistory = jline.console.history.PersistentHistory
-
private[interpreter] implicit def charSequenceFix(x: CharSequence): String = x.toString
}
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala
index b541cf721b..320a8e23b2 100644
--- a/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala
+++ b/src/scaladoc/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala
@@ -383,7 +383,7 @@ class DotDiagramGenerator(settings: doc.Settings, dotRunner: DotRunner) extends
if (dotId.count(_ == '|') == 1) {
val Array(klass, id) = dotId.toString.split("\\|")
/* Sometimes dot "forgets" to add the image -- that's very annoying, but it seems pretty random, and simple
- * tests like excute 20K times and diff the output don't trigger the bug -- so it's up to us to place the image
+ * tests like execute 20K times and diff the output don't trigger the bug -- so it's up to us to place the image
* back in the node */
val kind = getKind(klass)
if (kind != "")
diff --git a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
index 03d71f15a3..3cbcbc433e 100644
--- a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
+++ b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
@@ -478,7 +478,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
override lazy val comment = {
def nonRootTemplate(sym: Symbol): Option[DocTemplateImpl] =
if (sym eq RootPackage) None else findTemplateMaybe(sym)
- /* Variable precendence order for implicitly added members: Take the variable defifinitions from ...
+ /* Variable precendence order for implicitly added members: Take the variable definitions from ...
* 1. the target of the implicit conversion
* 2. the definition template (owner)
* 3. the current template
diff --git a/test/files/jvm/unreachable/Test.scala b/test/files/jvm/unreachable/Test.scala
index 3f520eb106..4c0fcb2ae8 100644
--- a/test/files/jvm/unreachable/Test.scala
+++ b/test/files/jvm/unreachable/Test.scala
@@ -6,7 +6,7 @@ import scala.collection.JavaConverters._
object Test extends BytecodeTest {
def show: Unit = {
val classNode = loadClassNode("Foo_1")
- // Foo_1 is full of unreachable code which if not elimintated
+ // Foo_1 is full of unreachable code which if not eliminated
// will result in NOPs as can be confirmed by adding -Ydisable-unreachable-prevention
// to Foo_1.flags
for (methodNode <- classNode.methods.asScala) {
diff --git a/test/files/neg/t3995.scala b/test/files/neg/t3995.scala
index b03617ac86..c79f2a5865 100644
--- a/test/files/neg/t3995.scala
+++ b/test/files/neg/t3995.scala
@@ -27,6 +27,6 @@ object Test {
// can be accessed with unambiguous stable prefixes, the implicits infos
// which are members of these companion objects."
//
- // The skolem is stable, but it doen't seem much good to us
+ // The skolem is stable, but it does not seem much good to us
(new Lift).apply("")
}
diff --git a/test/files/neg/t8237-default.scala b/test/files/neg/t8237-default.scala
index f695aa523f..a4370046bd 100644
--- a/test/files/neg/t8237-default.scala
+++ b/test/files/neg/t8237-default.scala
@@ -1,4 +1,4 @@
-// This test case was extracte from `names-defaults-neg.scala`
+// This test case was extracted from `names-defaults-neg.scala`
// It pinpoints an improvement an error message that results from
// a type inference failure
object Test extends App {
diff --git a/test/files/neg/t8463.scala b/test/files/neg/t8463.scala
index 7c954fd834..1337f8bece 100644
--- a/test/files/neg/t8463.scala
+++ b/test/files/neg/t8463.scala
@@ -7,7 +7,7 @@ object Test {
/* If SI-8230 is fixed, and `viewExists` is changed to no longer leak
ambiguity errors, you might expect the check file for this test to
- change as folloes:
+ change as follows:
@@ -1,18 +1,10 @@
-t8463.scala:5: error: no type parameters for method apply: (activity:
diff --git a/test/files/pos/SI-4012-b.scala b/test/files/pos/SI-4012-b.scala
index 6bc8592766..f6d84963e4 100644
--- a/test/files/pos/SI-4012-b.scala
+++ b/test/files/pos/SI-4012-b.scala
@@ -6,7 +6,7 @@ object Sub extends Super[Int] {
// it is expected that super[Super].superb crashes, since
// specialization does parent class rewiring, and the super
// of Sub becomes Super$mcII$sp and not Super. But I consider
- // this normal behavior -- if you want, I can modify duplicatiors
+ // this normal behavior -- if you want, I can modify duplicators
// to make this work, but I consider it's best to keep this
// let the user know Super is not the superclass anymore.
// super[Super].superb - Vlad
diff --git a/test/files/pos/delambdafy-patterns.scala b/test/files/pos/delambdafy-patterns.scala
index 95d498629b..ca9eaa67e3 100644
--- a/test/files/pos/delambdafy-patterns.scala
+++ b/test/files/pos/delambdafy-patterns.scala
@@ -2,7 +2,7 @@ class DelambdafyPatterns {
def bar: Unit = ()
def wildcardPatternInTryCatch: Unit => Unit = (x: Unit) =>
// patterns in try..catch are preserved so we need to be
- // careful when it comes to free variable detction
+ // careful when it comes to free variable detection
// in particular a is _not_ free variable, also the
// `_` identifier has no symbol attached to it
try bar catch {
diff --git a/test/files/pos/t7200b.scala b/test/files/pos/t7200b.scala
index 9d579c6ef9..59be898fd0 100644
--- a/test/files/pos/t7200b.scala
+++ b/test/files/pos/t7200b.scala
@@ -10,7 +10,7 @@ trait Foo {
object O extends Foo {
def coflatMap[A <: T](f: A) = {
val f2 = coflatMap(f) // inferred in 2.9.2 / 2.10.0 as [Nothing]
- f2.t // so this does't type check.
+ f2.t // so this fails to type check.
f2
}
}
diff --git a/test/files/run/deeps.scala b/test/files/run/deeps.scala
index 6049cc6024..1546112ed5 100644
--- a/test/files/run/deeps.scala
+++ b/test/files/run/deeps.scala
@@ -3,7 +3,7 @@
//############################################################################
//############################################################################
-// need to revisit array equqality
+// need to revisit array equality
object Test {
def testEquals1 {
diff --git a/test/files/run/finally.scala b/test/files/run/finally.scala
index 2c01edaaef..b66354ca03 100644
--- a/test/files/run/finally.scala
+++ b/test/files/run/finally.scala
@@ -93,7 +93,7 @@ object Test extends App {
}
}
- // nested finallies with return value
+ // nested finally blocks with return value
def nestedFinalies: Int =
try {
try {
diff --git a/test/files/run/iq.scala b/test/files/run/iq.scala
index 1eb1d40e37..0ccf67a2e9 100644
--- a/test/files/run/iq.scala
+++ b/test/files/run/iq.scala
@@ -69,7 +69,7 @@ object iq {
val (_, q7) = q6.dequeue
//val q8 = q7 + 10 + 11 //deprecated
val q8 = q7.enqueue(10).enqueue(11)
- /* Test dequeu
+ /* Test dequeue
* Expected: q8: Queue(2,3,4,5,6,7,8,9,10,11)
*/
Console.println("q8: " + q8)
diff --git a/test/files/run/names-defaults.scala b/test/files/run/names-defaults.scala
index b7ed490cbc..c364425ec9 100644
--- a/test/files/run/names-defaults.scala
+++ b/test/files/run/names-defaults.scala
@@ -86,7 +86,7 @@ object Test extends App {
def f(a: Object) = "first"
val f: String => String = a => "second"
}
- println(t5.f(new Sub1())) // firsst
+ println(t5.f(new Sub1())) // first
println(t5.f("dfklj")) // second
object t6 {
diff --git a/test/files/run/nullable-lazyvals.scala b/test/files/run/nullable-lazyvals.scala
index c201e74e75..be5d82f3a7 100644
--- a/test/files/run/nullable-lazyvals.scala
+++ b/test/files/run/nullable-lazyvals.scala
@@ -24,7 +24,7 @@ object Test extends App {
// test that try-finally does not generated a liftedTry
// helper. This would already fail the first part of the test,
- // but this check will help diganose it (if the single access to a
+ // but this check will help diagnose it (if the single access to a
// private field does not happen directly in the lazy val, it won't
// be nulled).
for (f <- foo.getClass.getDeclaredMethods) {
diff --git a/test/files/run/t6240-universe-code-gen.scala b/test/files/run/t6240-universe-code-gen.scala
index 9f7061ee1b..60e1f76b54 100644
--- a/test/files/run/t6240-universe-code-gen.scala
+++ b/test/files/run/t6240-universe-code-gen.scala
@@ -13,8 +13,8 @@ object Test extends App {
(sym.isMethod && sym.asMethod.isLazy)
|| sym.isModule
)
- val forcables = tp.members.sorted.filter(isLazyAccessorOrObject)
- forcables.map {
+ val forceables = tp.members.sorted.filter(isLazyAccessorOrObject)
+ forceables.map {
sym =>
val path = s"$prefix.${sym.name}"
" " + (
diff --git a/test/files/run/t7582.check b/test/files/run/t7582.check
index 2a11210000..0cfbf08886 100644
--- a/test/files/run/t7582.check
+++ b/test/files/run/t7582.check
@@ -1,6 +1 @@
-#partest !-Ybackend:GenBCode
-warning: there was one inliner warning; re-run with -Yinline-warnings for details
-#partest -Ybackend:GenBCode
-warning: there was one inliner warning; re-run with -Yopt-warnings for details
-#partest
2
diff --git a/test/files/run/t7582/InlineHolder.scala b/test/files/run/t7582/InlineHolder.scala
index a18b9effaa..3cbf233ce1 100644
--- a/test/files/run/t7582/InlineHolder.scala
+++ b/test/files/run/t7582/InlineHolder.scala
@@ -1,3 +1,6 @@
+/*
+ * filter: inliner warning; re-run with
+ */
package p1 {
object InlineHolder {
@inline def inlinable = p1.PackageProtectedJava.protectedMethod() + 1
diff --git a/test/files/run/t7582b.check b/test/files/run/t7582b.check
index 2a11210000..0cfbf08886 100644
--- a/test/files/run/t7582b.check
+++ b/test/files/run/t7582b.check
@@ -1,6 +1 @@
-#partest !-Ybackend:GenBCode
-warning: there was one inliner warning; re-run with -Yinline-warnings for details
-#partest -Ybackend:GenBCode
-warning: there was one inliner warning; re-run with -Yopt-warnings for details
-#partest
2
diff --git a/test/files/run/t7582b/InlineHolder.scala b/test/files/run/t7582b/InlineHolder.scala
index a18b9effaa..3cbf233ce1 100644
--- a/test/files/run/t7582b/InlineHolder.scala
+++ b/test/files/run/t7582b/InlineHolder.scala
@@ -1,3 +1,6 @@
+/*
+ * filter: inliner warning; re-run with
+ */
package p1 {
object InlineHolder {
@inline def inlinable = p1.PackageProtectedJava.protectedMethod() + 1
diff --git a/test/files/run/t8601-closure-elim.scala b/test/files/run/t8601-closure-elim.scala
index 2c5b03af77..ebeb16e0c7 100644
--- a/test/files/run/t8601-closure-elim.scala
+++ b/test/files/run/t8601-closure-elim.scala
@@ -11,7 +11,7 @@ object Test extends BytecodeTest {
val classNode = loadClassNode("Foo")
val methodNode = getMethod(classNode, "b")
val ops = methodNode.instructions.iterator.asScala.map(_.getOpcode).toList
- assert(!ops.contains(asm.Opcodes.NEW), ops)// should be allocation free if the closure is eliminiated
+ assert(!ops.contains(asm.Opcodes.NEW), ops)// should be allocation free if the closure is eliminated
}
test("b")
}
diff --git a/test/files/run/t8708_b/Test_2.scala b/test/files/run/t8708_b/Test_2.scala
index c978490609..fae3c677ec 100644
--- a/test/files/run/t8708_b/Test_2.scala
+++ b/test/files/run/t8708_b/Test_2.scala
@@ -13,7 +13,7 @@ object Test extends DirectTest {
val c = g.rootMirror.getRequiredClass("p.C")
println(c.info.decls)
val t = c.info.member(g.newTypeName("T"))
- // this test ensrues that the <local child> dummy class symbol is not entered in the
+ // this test ensures that the <local child> dummy class symbol is not entered in the
// scope of trait T during unpickling.
println(t.info.decls)
})
diff --git a/test/files/run/t9359.check b/test/files/run/t9359.check
new file mode 100644
index 0000000000..8dcfe4f60a
--- /dev/null
+++ b/test/files/run/t9359.check
@@ -0,0 +1,18 @@
+ // access flags 0x4009
+ public static enum INNERCLASS A_1$A1N A_1 A1N
+
+ // access flags 0x4409
+ public static abstract enum INNERCLASS A_1$A1N_ABSTRACT A_1 A1N_ABSTRACT
+
+ // access flags 0x4019
+ public final static enum INNERCLASS A_1$A1N_FINAL A_1 A1N_FINAL
+
+ // access flags 0x4009
+ public static enum INNERCLASS B_2$A1N B_2 A1N
+
+ // access flags 0x4409
+ public static abstract enum INNERCLASS B_2$A1N_ABSTRACT B_2 A1N_ABSTRACT
+
+ // access flags 0x4019
+ public final static enum INNERCLASS B_2$A1N_FINAL B_2 A1N_FINAL
+
diff --git a/test/files/run/t9359/A_1.java b/test/files/run/t9359/A_1.java
new file mode 100644
index 0000000000..3ac82ed55f
--- /dev/null
+++ b/test/files/run/t9359/A_1.java
@@ -0,0 +1,19 @@
+public class A_1 {
+ // nested final
+ public static enum A1N_FINAL {
+ A1N_FINAL_VAL
+ }
+
+ // nested, non-final
+ public enum A1N {
+ A1N_VAL { } // value has a body, so a class extending A1N is generated
+ }
+
+ // nested, non-final, abstract
+ public enum A1N_ABSTRACT {
+ A1N_ABSTRACT_VAL {
+ void foo() { return; }
+ };
+ abstract void foo(); // abstract member makes the enum class abstract
+ }
+}
diff --git a/test/files/run/t9359/B_2.java b/test/files/run/t9359/B_2.java
new file mode 100644
index 0000000000..d824facda9
--- /dev/null
+++ b/test/files/run/t9359/B_2.java
@@ -0,0 +1,19 @@
+public class B_2 {
+ // nested final
+ public enum A1N_FINAL {
+ A1N_FINAL_VAL
+ }
+
+ // nested, non-final
+ public enum A1N {
+ A1N_VAL { } // value has a body, so a class extending A1N is generated
+ }
+
+ // nested, non-final, abstract
+ public enum A1N_ABSTRACT {
+ A1N_ABSTRACT_VAL {
+ void foo() { return; }
+ };
+ abstract void foo(); // abstract member makes the enum class abstract
+ }
+}
diff --git a/test/files/run/t9359/Test_2.scala b/test/files/run/t9359/Test_2.scala
new file mode 100644
index 0000000000..869c51b619
--- /dev/null
+++ b/test/files/run/t9359/Test_2.scala
@@ -0,0 +1,28 @@
+import scala.tools.partest.BytecodeTest
+import scala.tools.asm
+import asm.tree.{ClassNode, InnerClassNode}
+import asm.{Opcodes => Flags}
+import scala.collection.JavaConverters._
+
+class C {
+ def f1: A_1.A1N_FINAL = A_1.A1N_FINAL.A1N_FINAL_VAL
+ def f2: A_1.A1N = A_1.A1N.A1N_VAL
+ def f3: A_1.A1N_ABSTRACT = A_1.A1N_ABSTRACT.A1N_ABSTRACT_VAL
+
+ def f4: B_2.A1N_FINAL = B_2.A1N_FINAL.A1N_FINAL_VAL
+ def f5: B_2.A1N = B_2.A1N.A1N_VAL
+ def f6: B_2.A1N_ABSTRACT = B_2.A1N_ABSTRACT.A1N_ABSTRACT_VAL
+}
+
+object Test extends BytecodeTest {
+ def tost(n: InnerClassNode) = {
+ val t = new asm.util.Textifier
+ t.visitInnerClass(n.name, n.outerName, n.innerName, n.access)
+ t.getText.get(0);
+ }
+ def show(): Unit = {
+ for (n <- loadClassNode("C").innerClasses.asScala.toList.sortBy(_.name)) {
+ println(tost(n))
+ }
+ }
+}
diff --git a/test/files/specialized/constant_lambda.scala b/test/files/specialized/constant_lambda.scala
index bb9a97403e..7c5358ce10 100644
--- a/test/files/specialized/constant_lambda.scala
+++ b/test/files/specialized/constant_lambda.scala
@@ -1,4 +1,4 @@
-// during development of late delmabdafying there was a problem where
+// during development of late delambdafying there was a problem where
// specialization would undo some of the work done in uncurry if the body of the
// lambda had a constant type. That would result in a compiler crash as
// when the delambdafy phase got a tree shape it didn't understand
diff --git a/test/scaladoc/run/groups.scala b/test/scaladoc/run/groups.scala
index c9e4a8679b..ad5cca89b8 100644
--- a/test/scaladoc/run/groups.scala
+++ b/test/scaladoc/run/groups.scala
@@ -38,7 +38,7 @@ object Test extends ScaladocModelTest {
* @groupdesc C Group C is introduced by B
*/
trait B {
- /** baz descriptopn
+ /** baz description
* @group C */
def baz = 3
}