summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-01-29 09:59:54 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-01-29 09:59:54 +1000
commit1db62995b52b06f5037331172b3f54739d720d62 (patch)
tree0b684c4adfcb800fa195947b37fdb5dc89731552
parent8b5f2b435b4b14089806406c8923f7e845d10ef6 (diff)
parenteb15950e697eb77e52733f81c65e2d51951ad881 (diff)
downloadscala-1db62995b52b06f5037331172b3f54739d720d62.tar.gz
scala-1db62995b52b06f5037331172b3f54739d720d62.tar.bz2
scala-1db62995b52b06f5037331172b3f54739d720d62.zip
Merge commit 'eb15950' into merge/2.11.x-to-2.12.x-20150129
-rwxr-xr-xbuild.xml2
-rw-r--r--spec/02-identifiers-names-and-scopes.md2
-rw-r--r--spec/03-types.md14
-rw-r--r--spec/04-basic-declarations-and-definitions.md2
-rw-r--r--spec/06-expressions.md6
-rw-r--r--spec/08-pattern-matching.md4
-rw-r--r--spec/10-xml-expressions-and-patterns.md2
-rw-r--r--spec/12-the-scala-standard-library.md2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala32
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala29
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala82
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala83
-rw-r--r--src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala2
-rw-r--r--src/compiler/scala/tools/nsc/settings/AbsSettings.scala6
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala25
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Delambdafy.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Flatten.scala7
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/Logic.scala17
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala56
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala18
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/Solving.scala96
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala41
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala32
-rw-r--r--src/library/scala/collection/immutable/Range.scala8
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala12
-rw-r--r--src/library/scala/collection/mutable/PriorityQueue.scala5
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala7
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala61
-rw-r--r--src/reflect/scala/reflect/internal/pickling/UnPickler.scala12
-rw-r--r--src/reflect/scala/reflect/internal/util/AbstractFileClassLoader.scala66
-rw-r--r--src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala6
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala2
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala117
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala34
-rw-r--r--src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala23
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplProps.scala3
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplReporter.scala18
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplStrings.scala5
-rw-r--r--src/scaladoc/scala/tools/nsc/ScalaDoc.scala20
-rw-r--r--test/files/neg/patmatexhaust.check2
-rw-r--r--test/files/neg/patmatexhaust.flags2
-rw-r--r--test/files/neg/patmatexhaust.scala2
-rw-r--r--test/files/neg/t3240.check4
-rw-r--r--test/files/neg/t6902.scala2
-rw-r--r--test/files/neg/t8217-local-alias-requires-rhs.check10
-rw-r--r--test/files/neg/t8217-local-alias-requires-rhs.scala15
-rw-r--r--test/files/neg/t8291.check7
-rw-r--r--test/files/neg/t8291.scala7
-rw-r--r--test/files/neg/t8430.check12
-rw-r--r--test/files/neg/t8430.flags2
-rw-r--r--test/files/neg/t845.check4
-rw-r--r--test/files/neg/t8731.check9
-rw-r--r--test/files/neg/t8731.flags1
-rw-r--r--test/files/neg/t8731.scala15
-rw-r--r--test/files/neg/t8869.check7
-rw-r--r--test/files/neg/t8869.scala10
-rw-r--r--test/files/neg/t8890.check4
-rw-r--r--test/files/neg/t8890.scala11
-rw-r--r--test/files/pos/switch-small.flags1
-rw-r--r--test/files/pos/switch-small.scala8
-rw-r--r--test/files/pos/t3240.scala (renamed from test/files/neg/t3240.scala)0
-rw-r--r--test/files/pos/t8267.scala33
-rw-r--r--test/files/pos/t845.scala (renamed from test/files/neg/t845.scala)0
-rw-r--r--test/files/pos/t8868a/Sub_2.scala1
-rw-r--r--test/files/pos/t8868a/T_1.scala6
-rw-r--r--test/files/pos/t8868b/Sub_2.scala2
-rw-r--r--test/files/pos/t8868b/T_1.scala4
-rw-r--r--test/files/pos/t8868c/Sub_2.scala2
-rw-r--r--test/files/pos/t8868c/T_1.scala9
-rw-r--r--test/files/pos/t8894.scala12
-rw-r--r--test/files/presentation/doc.check (renamed from test/disabled/presentation/doc.check)0
-rwxr-xr-xtest/files/presentation/doc/doc.scala (renamed from test/disabled/presentation/doc/doc.scala)0
-rwxr-xr-xtest/files/presentation/doc/src/Class.scala (renamed from test/disabled/presentation/doc/src/Class.scala)0
-rwxr-xr-xtest/files/presentation/doc/src/p/Base.scala (renamed from test/disabled/presentation/doc/src/p/Base.scala)0
-rwxr-xr-xtest/files/presentation/doc/src/p/Derived.scala (renamed from test/disabled/presentation/doc/src/p/Derived.scala)0
-rw-r--r--test/files/run/t4594-repl-settings.scala2
-rw-r--r--test/files/run/t4788-separate-compilation.check5
-rw-r--r--test/files/run/t4788-separate-compilation/CAnnotation_1.java5
-rw-r--r--test/files/run/t4788-separate-compilation/C_1.scala2
-rw-r--r--test/files/run/t4788-separate-compilation/D_1.scala5
-rw-r--r--test/files/run/t4788-separate-compilation/RAnnotation_1.java5
-rw-r--r--test/files/run/t4788-separate-compilation/R_1.scala2
-rw-r--r--test/files/run/t4788-separate-compilation/SAnnotation_1.java5
-rw-r--r--test/files/run/t4788-separate-compilation/S_1.scala2
-rw-r--r--test/files/run/t4788-separate-compilation/Test_2.scala35
-rw-r--r--test/files/run/t4788.check5
-rw-r--r--test/files/run/t4788/C.scala2
-rw-r--r--test/files/run/t4788/CAnnotation.java5
-rw-r--r--test/files/run/t4788/D.scala5
-rw-r--r--test/files/run/t4788/R.scala2
-rw-r--r--test/files/run/t4788/RAnnotation.java5
-rw-r--r--test/files/run/t4788/S.scala2
-rw-r--r--test/files/run/t4788/SAnnotation.java5
-rw-r--r--test/files/run/t4788/Test.scala35
-rw-r--r--test/files/run/t5830.check1
-rw-r--r--test/files/run/t5830.scala13
-rw-r--r--test/files/run/t6011c.scala2
-rw-r--r--test/files/run/t6622.check10
-rw-r--r--test/files/run/t6622.scala50
-rw-r--r--test/files/run/t8087.scala12
-rw-r--r--test/files/run/t8445.check1
-rw-r--r--test/files/run/t8445.scala11
-rw-r--r--test/files/run/t8843-repl-xlat.scala33
-rw-r--r--test/files/run/t8845.flags1
-rw-r--r--test/files/run/t8845.scala17
-rw-r--r--test/files/run/t8888.flags1
-rw-r--r--test/files/run/t8888.scala12
-rw-r--r--test/files/run/t8907.scala39
-rw-r--r--test/files/run/virtpatmat_nested_lists.flags1
-rw-r--r--test/files/run/virtpatmat_opt_sharing.flags1
-rw-r--r--test/junit/scala/collection/immutable/PagedSeqTest.scala (renamed from test/junit/scala/collection/PagedSeq.scala)0
-rw-r--r--test/junit/scala/collection/immutable/QueueTest.scala (renamed from test/junit/scala/collection/QueueTest.scala)0
-rw-r--r--test/junit/scala/collection/immutable/RangeConsistencyTest.scala (renamed from test/junit/scala/collection/NumericRangeTest.scala)0
-rw-r--r--test/junit/scala/collection/immutable/StreamTest.scala (renamed from test/junit/scala/collection/StreamTest.scala)0
-rw-r--r--test/junit/scala/collection/mutable/ArraySortingTest.scala (renamed from test/junit/scala/collection/ArraySortingTest.scala)0
-rw-r--r--test/junit/scala/collection/mutable/PriorityQueueTest.scala (renamed from test/junit/scala/collection/PriorityQueueTest.scala)0
-rw-r--r--test/junit/scala/collection/mutable/VectorTest.scala (renamed from test/junit/scala/collection/VectorTest.scala)0
-rw-r--r--test/junit/scala/issues/BytecodeTests.scala39
-rw-r--r--test/junit/scala/math/NumericTest.scala2
-rw-r--r--test/junit/scala/reflect/internal/PrintersTest.scala6
-rw-r--r--test/junit/scala/reflect/internal/ScopeTest.scala2
-rw-r--r--test/junit/scala/reflect/internal/util/AbstractFileClassLoaderTest.scala138
-rw-r--r--test/junit/scala/tools/nsc/SampleTest.scala1
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala3
-rw-r--r--test/junit/scala/util/SpecVersionTest.scala (renamed from test/junit/scala/util/t7265.scala)4
-rw-r--r--test/junit/scala/util/matching/CharRegexTest.scala (renamed from test/junit/scala/util/matching/regextract-char.scala)0
130 files changed, 1273 insertions, 435 deletions
diff --git a/build.xml b/build.xml
index 69220169a9..4589d991d3 100755
--- a/build.xml
+++ b/build.xml
@@ -1437,7 +1437,7 @@ TODO:
<stopwatch name="test.junit.compiler.timer" action="total"/>
</target>
- <target name="test.junit" depends="test.junit.comp">
+ <target name="test.junit" depends="test.junit.comp, test.junit.init">
<stopwatch name="test.junit.timer"/>
<mkdir dir="${test.junit.classes}"/>
<echo message="Note: details of failed tests will be output to ${build-junit.dir}"/>
diff --git a/spec/02-identifiers-names-and-scopes.md b/spec/02-identifiers-names-and-scopes.md
index afa97c136c..62d326934f 100644
--- a/spec/02-identifiers-names-and-scopes.md
+++ b/spec/02-identifiers-names-and-scopes.md
@@ -71,7 +71,7 @@ The type of $e.x$ is the member type of the referenced entity in $T$.
### Example
-Assume the following two definitions of a objects named `X` in packages `P` and `Q`.
+Assume the following two definitions of objects named `X` in packages `P` and `Q`.
```scala
package P {
diff --git a/spec/03-types.md b/spec/03-types.md
index 80200cdf33..d067d45ab2 100644
--- a/spec/03-types.md
+++ b/spec/03-types.md
@@ -821,7 +821,7 @@ the following holds:
parameters by another, the result types as well as variances, lower and upper
bounds of corresponding type parameters are equivalent.
-[^congruence]: A congruence is an equivalence relation which is closed under formation of contexts
+[^congruence]: A congruence is an equivalence relation which is closed under formation of contexts.
[^implicit]: A method type is implicit if the parameter section that defines it starts with the `implicit` keyword.
### Conformance
@@ -864,15 +864,15 @@ transitive relation that satisfies the following conditions.
if $T$ conforms to one of the [type instances](#existential-types)
of `$U$ forSome {$\,Q\,$}`.
- If
- $T_i \equiv T'_i$ for $i \in \{ 1 , \ldots , n\}$ and $U$ conforms to $U'$
+ $T_i \equiv T_i'$ for $i \in \{ 1 , \ldots , n\}$ and $U$ conforms to $U'$
then the method type $(p_1:T_1 , \ldots , p_n:T_n) U$ conforms to
- $(p'_1:T'_1 , \ldots , p'_n:T'_n) U'$.
+ $(p_1':T_1' , \ldots , p_n':T_n') U'$.
- The polymorphic type
$[a_1 >: L_1 <: U_1 , \ldots , a_n >: L_n <: U_n] T$ conforms to the
polymorphic type
- $[a_1 >: L'_1 <: U'_1 , \ldots , a_n >: L'_n <: U'_n] T'$ if, assuming
- $L'_1 <: a_1 <: U'_1 , \ldots , L'_n <: a_n <: U'_n$
- one has $T <: T'$ and $L_i <: L'_i$ and $U'_i <: U_i$
+ $[a_1 >: L_1' <: U_1' , \ldots , a_n >: L_n' <: U_n'] T'$ if, assuming
+ $L_1' <: a_1 <: U_1' , \ldots , L_n' <: a_n <: U_n'$
+ one has $T <: T'$ and $L_i <: L_i'$ and $U_i' <: U_i$
for $i \in \{ 1 , \ldots , n \}$.
- Type constructors $T$ and $T'$ follow a similar discipline. We characterize
$T$ and $T'$ by their type parameter clauses
@@ -939,7 +939,7 @@ limit [^4].
The least upper bound or greatest lower bound might also not be
unique. For instance `A with B` and `B with A` are both
-greatest lower of `A` and `B`. If there are several
+greatest lower bounds of `A` and `B`. If there are several
least upper bounds or greatest lower bounds, the Scala compiler is
free to pick any one of them.
diff --git a/spec/04-basic-declarations-and-definitions.md b/spec/04-basic-declarations-and-definitions.md
index ed7e4c625e..aca1c63d22 100644
--- a/spec/04-basic-declarations-and-definitions.md
+++ b/spec/04-basic-declarations-and-definitions.md
@@ -720,7 +720,7 @@ variable number of integer arguments.
```scala
def sum(args: Int*) = {
var result = 0
- for (arg <- args) result += arg * arg
+ for (arg <- args) result += arg
result
}
```
diff --git a/spec/06-expressions.md b/spec/06-expressions.md
index 03b8065f4b..afd1492744 100644
--- a/spec/06-expressions.md
+++ b/spec/06-expressions.md
@@ -1571,7 +1571,7 @@ $T$ is a value type; if it is a method type we apply
means finding a substitution $\sigma$ of types $T_i$ for the type
parameters $a_i$ such that
-- None of inferred types $T_i$ is a [singleton type](03-types.html#singleton-types)
+- None of the inferred types $T_i$ is a [singleton type](03-types.html#singleton-types)
- All type parameter bounds are respected, i.e.
$\sigma L_i <: \sigma a_i$ and $\sigma a_i <: \sigma U_i$ for $i = 1 , \ldots , n$.
- The expression's type conforms to the expected type, i.e.
@@ -1608,7 +1608,7 @@ constraint system means
finding a substitution $\sigma$ of types $T_i$ for the type parameters
$a_i$ such that
-- None of inferred types $T_i$ is a [singleton type](03-types.html#singleton-types)
+- None of the inferred types $T_i$ is a [singleton type](03-types.html#singleton-types)
- All type parameter bounds are respected, i.e. $\sigma L_i <: \sigma a_i$ and
$\sigma a_i <: \sigma U_i$ for $i = 1 , \ldots , n$.
- The method's result type $T'$ conforms to the expected type, i.e. $\sigma T' <: \sigma \mathit{pt}$.
@@ -1750,7 +1750,7 @@ a sub-expression of parameterless method type, is not evaluated in the expanded
### Dynamic Member Selection
The standard Scala library defines a trait `scala.Dynamic` which defines a member
-\@invokeDynamic@ as follows:
+`applyDynamic` as follows:
```scala
package scala
diff --git a/spec/08-pattern-matching.md b/spec/08-pattern-matching.md
index 8e224de8d2..3538457b5c 100644
--- a/spec/08-pattern-matching.md
+++ b/spec/08-pattern-matching.md
@@ -115,7 +115,7 @@ type of the pattern. The pattern matches any value $v$ such that
To resolve the syntactic overlap with a variable pattern, a
stable identifier pattern may not be a simple name starting with a lower-case
-letter. However, it is possible to enclose a such a variable name in
+letter. However, it is possible to enclose such a variable name in
backquotes; then it is treated as a stable identifier pattern.
###### Example
@@ -283,7 +283,7 @@ shorthand for the constructor or extractor pattern $\mathit{op}(p, q_1
A pattern alternative `$p_1$ | $\ldots$ | $p_n$`
consists of a number of alternative patterns $p_i$. All alternative
patterns are type checked with the expected type of the pattern. They
-may no bind variables other than wildcards. The alternative pattern
+may not bind variables other than wildcards. The alternative pattern
matches a value $v$ if at least one its alternatives matches $v$.
### XML Patterns
diff --git a/spec/10-xml-expressions-and-patterns.md b/spec/10-xml-expressions-and-patterns.md
index 069f499ce9..407b2b9a67 100644
--- a/spec/10-xml-expressions-and-patterns.md
+++ b/spec/10-xml-expressions-and-patterns.md
@@ -59,7 +59,7 @@ sequence of XML nodes (an instance of a subclass of
`scala.Seq[scala.xml.Node]`).
If an XML expression is an entity reference, CDATA section, processing
-instructions or a comments, it is represented by an instance of the
+instruction, or a comment, it is represented by an instance of the
corresponding Scala runtime class.
By default, beginning and trailing whitespace in element content is removed,
diff --git a/spec/12-the-scala-standard-library.md b/spec/12-the-scala-standard-library.md
index 2b3ac1742c..988d9804ec 100644
--- a/spec/12-the-scala-standard-library.md
+++ b/spec/12-the-scala-standard-library.md
@@ -332,7 +332,7 @@ The `toString` method returns `"()"`.
## Standard Reference Classes
This section presents some standard Scala reference classes which are
-treated in a special way in Scala compiler -- either Scala provides
+treated in a special way by the Scala compiler -- either Scala provides
syntactic sugar for them, or the Scala compiler generates special code
for their operations. Other classes in the standard Scala library are
documented in the Scala library documentation by HTML pages.
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
index 0c0d726630..4285858bf8 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
@@ -14,6 +14,13 @@ import PartialFunction._
*/
final class BCodeAsmCommon[G <: Global](val global: G) {
import global._
+ import definitions._
+
+ val ExcludedForwarderFlags = {
+ import scala.tools.nsc.symtab.Flags._
+ // Should include DEFERRED but this breaks findMember.
+ ( SPECIALIZED | LIFTED | PROTECTED | STATIC | EXPANDEDNAME | BridgeAndPrivateFlags | MACRO )
+ }
/**
* True if `classSym` is an anonymous class or a local class. I.e., false if `classSym` is a
@@ -124,4 +131,29 @@ final class BCodeAsmCommon[G <: Global](val global: G) {
assert(r != NoSymbol, sym.fullLocationString)
r
})(collection.breakOut)
+
+ lazy val AnnotationRetentionPolicyModule = AnnotationRetentionPolicyAttr.companionModule
+ lazy val AnnotationRetentionPolicySourceValue = AnnotationRetentionPolicyModule.tpe.member(TermName("SOURCE"))
+ lazy val AnnotationRetentionPolicyClassValue = AnnotationRetentionPolicyModule.tpe.member(TermName("CLASS"))
+ lazy val AnnotationRetentionPolicyRuntimeValue = AnnotationRetentionPolicyModule.tpe.member(TermName("RUNTIME"))
+
+ /** Whether an annotation should be emitted as a Java annotation
+ * .initialize: if 'annot' is read from pickle, atp might be un-initialized
+ */
+ def shouldEmitAnnotation(annot: AnnotationInfo) = {
+ annot.symbol.initialize.isJavaDefined &&
+ annot.matches(ClassfileAnnotationClass) &&
+ retentionPolicyOf(annot) != AnnotationRetentionPolicySourceValue &&
+ annot.args.isEmpty
+ }
+
+ def isRuntimeVisible(annot: AnnotationInfo): Boolean =
+ annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr)
+ .exists(_.assocs.contains((nme.value -> LiteralAnnotArg(Constant(AnnotationRetentionPolicyRuntimeValue)))))
+
+ private def retentionPolicyOf(annot: AnnotationInfo): Symbol =
+ annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr).map(_.assocs).map(assoc =>
+ assoc.collectFirst {
+ case (`nme`.value, LiteralAnnotArg(Constant(value: Symbol))) => value
+ }).flatten.getOrElse(AnnotationRetentionPolicyClassValue)
}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
index 14bffd67ab..806d4b277c 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
@@ -469,6 +469,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
trait BCAnnotGen extends BCInnerClassGen {
import genASM.{ubytesToCharArray, arrEncode}
+ import bCodeAsmCommon.{shouldEmitAnnotation, isRuntimeVisible}
/*
* can-multi-thread
@@ -533,17 +534,6 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
}
}
- /* Whether an annotation should be emitted as a Java annotation
- * .initialize: if 'annot' is read from pickle, atp might be un-initialized
- *
- * must-single-thread
- */
- private def shouldEmitAnnotation(annot: AnnotationInfo) =
- annot.symbol.initialize.isJavaDefined &&
- annot.matches(definitions.ClassfileAnnotationClass) &&
- annot.args.isEmpty &&
- !annot.matches(definitions.DeprecatedAttr)
-
/*
* In general,
* must-single-thread
@@ -563,7 +553,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val av = cw.visitAnnotation(descriptor(typ), true)
+ val av = cw.visitAnnotation(descriptor(typ), isRuntimeVisible(annot))
emitAssocs(av, assocs)
}
}
@@ -575,7 +565,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val av = mw.visitAnnotation(descriptor(typ), true)
+ val av = mw.visitAnnotation(descriptor(typ), isRuntimeVisible(annot))
emitAssocs(av, assocs)
}
}
@@ -587,7 +577,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val av = fw.visitAnnotation(descriptor(typ), true)
+ val av = fw.visitAnnotation(descriptor(typ), isRuntimeVisible(annot))
emitAssocs(av, assocs)
}
}
@@ -602,7 +592,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
annot <- annots) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val pannVisitor: asm.AnnotationVisitor = jmethod.visitParameterAnnotation(idx, descriptor(typ), true)
+ val pannVisitor: asm.AnnotationVisitor = jmethod.visitParameterAnnotation(idx, descriptor(typ), isRuntimeVisible(annot))
emitAssocs(pannVisitor, assocs)
}
}
@@ -625,13 +615,6 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
trait BCForwardersGen extends BCAnnotGen with BCJGenSigGen {
- // -----------------------------------------------------------------------------------------
- // Static forwarders (related to mirror classes but also present in
- // a plain class lacking companion module, for details see `isCandidateForForwarders`).
- // -----------------------------------------------------------------------------------------
-
- val ExcludedForwarderFlags = genASM.ExcludedForwarderFlags
-
/* Adds a @remote annotation, actual use unknown.
*
* Invoked from genMethod() and addForwarder().
@@ -727,7 +710,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
}
debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")
- for (m <- moduleClass.info.membersBasedOnFlags(ExcludedForwarderFlags, symtab.Flags.METHOD)) {
+ for (m <- moduleClass.info.membersBasedOnFlags(bCodeAsmCommon.ExcludedForwarderFlags, symtab.Flags.METHOD)) {
if (m.isType || m.isDeferred || (m.owner eq definitions.ObjectClass) || m.isConstructor)
debuglog(s"No forwarder for '$m' from $jclassName to '$moduleClass'")
else if (conflictingNames(m.name))
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index 2593903b9d..d0a12c32e5 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -20,7 +20,7 @@ import scala.annotation.tailrec
*
* Documentation at http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/2012Q2/GenASM.pdf
*/
-abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { self =>
+abstract class GenASM extends SubComponent with BytecodeWriters { self =>
import global._
import icodes._
import icodes.opcodes._
@@ -99,17 +99,76 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
}
}
+ private def isJavaEntryPoint(icls: IClass) = {
+ val sym = icls.symbol
+ def fail(msg: String, pos: Position = sym.pos) = {
+ reporter.warning(sym.pos,
+ sym.name + " has a main method with parameter type Array[String], but " + sym.fullName('.') + " will not be a runnable program.\n" +
+ " Reason: " + msg
+ // TODO: make this next claim true, if possible
+ // by generating valid main methods as static in module classes
+ // not sure what the jvm allows here
+ // + " You can still run the program by calling it as " + sym.javaSimpleName + " instead."
+ )
+ false
+ }
+ def failNoForwarder(msg: String) = {
+ fail(msg + ", which means no static forwarder can be generated.\n")
+ }
+ val possibles = if (sym.hasModuleFlag) (sym.tpe nonPrivateMember nme.main).alternatives else Nil
+ val hasApproximate = possibles exists { m =>
+ m.info match {
+ case MethodType(p :: Nil, _) => p.tpe.typeSymbol == ArrayClass
+ case _ => false
+ }
+ }
+ // At this point it's a module with a main-looking method, so either succeed or warn that it isn't.
+ hasApproximate && {
+ // Before erasure so we can identify generic mains.
+ enteringErasure {
+ val companion = sym.linkedClassOfClass
+
+ if (hasJavaMainMethod(companion))
+ failNoForwarder("companion contains its own main method")
+ else if (companion.tpe.member(nme.main) != NoSymbol)
+ // this is only because forwarders aren't smart enough yet
+ failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
+ else if (companion.isTrait)
+ failNoForwarder("companion is a trait")
+ // Now either succeeed, or issue some additional warnings for things which look like
+ // attempts to be java main methods.
+ else (possibles exists isJavaMainMethod) || {
+ possibles exists { m =>
+ m.info match {
+ case PolyType(_, _) =>
+ fail("main methods cannot be generic.")
+ case MethodType(params, res) =>
+ if (res.typeSymbol :: params exists (_.isAbstractType))
+ fail("main methods cannot refer to type parameters or abstract types.", m.pos)
+ else
+ isJavaMainMethod(m) || fail("main method must have exact signature (Array[String])Unit", m.pos)
+ case tp =>
+ fail("don't know what this is: " + tp, m.pos)
+ }
+ }
+ }
+ }
+ }
+ }
+
override def run() {
if (settings.debug)
inform("[running phase " + name + " on icode]")
- if (settings.Xdce)
- for ((sym, cls) <- icodes.classes if inliner.isClosureClass(sym) && !deadCode.liveClosures(sym)) {
+ if (settings.Xdce) {
+ val classes = icodes.classes.keys.toList // copy to avoid mutating the map while iterating
+ for (sym <- classes if inliner.isClosureClass(sym) && !deadCode.liveClosures(sym)) {
log(s"Optimizer eliminated ${sym.fullNameString}")
deadCode.elidedClosures += sym
icodes.classes -= sym
}
+ }
// For predictably ordered error messages.
var sortedClasses = classes.values.toList sortBy (_.symbol.fullName)
@@ -805,15 +864,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
for (ThrownException(exc) <- excs.distinct)
yield javaName(exc)
- /** Whether an annotation should be emitted as a Java annotation
- * .initialize: if 'annot' is read from pickle, atp might be un-initialized
- */
- private def shouldEmitAnnotation(annot: AnnotationInfo) =
- annot.symbol.initialize.isJavaDefined &&
- annot.matches(ClassfileAnnotationClass) &&
- annot.args.isEmpty &&
- !annot.matches(DeprecatedAttr)
-
def getCurrentCUnit(): CompilationUnit
def getGenericSignature(sym: Symbol, owner: Symbol) = self.getGenericSignature(sym, owner, getCurrentCUnit())
@@ -875,7 +925,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val av = cw.visitAnnotation(descriptor(typ), true)
+ val av = cw.visitAnnotation(descriptor(typ), isRuntimeVisible(annot))
emitAssocs(av, assocs)
}
}
@@ -884,7 +934,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val av = mw.visitAnnotation(descriptor(typ), true)
+ val av = mw.visitAnnotation(descriptor(typ), isRuntimeVisible(annot))
emitAssocs(av, assocs)
}
}
@@ -893,7 +943,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val av = fw.visitAnnotation(descriptor(typ), true)
+ val av = fw.visitAnnotation(descriptor(typ), isRuntimeVisible(annot))
emitAssocs(av, assocs)
}
}
@@ -905,7 +955,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
annot <- annots) {
val AnnotationInfo(typ, args, assocs) = annot
assert(args.isEmpty, args)
- val pannVisitor: asm.AnnotationVisitor = jmethod.visitParameterAnnotation(idx, descriptor(typ), true)
+ val pannVisitor: asm.AnnotationVisitor = jmethod.visitParameterAnnotation(idx, descriptor(typ), isRuntimeVisible(annot))
emitAssocs(pannVisitor, assocs)
}
}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala
deleted file mode 100644
index 2bcde7f7b9..0000000000
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala
+++ /dev/null
@@ -1,83 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Jason Zaugg
- */
-
-package scala.tools.nsc
-package backend.jvm
-import scala.tools.nsc.symtab._
-
-/** Code shared between the erstwhile legacy backend (aka GenJVM)
- * and the new backend [[scala.tools.nsc.backend.jvm.GenASM]]. There should be
- * more here, but for now I'm starting with the refactorings that are either
- * straightforward to review or necessary for maintenance.
- */
-trait GenJVMASM {
- val global: Global
- import global._
- import icodes._
- import definitions._
-
- val ExcludedForwarderFlags = {
- import Flags._
- // Should include DEFERRED but this breaks findMember.
- ( SPECIALIZED | LIFTED | PROTECTED | STATIC | EXPANDEDNAME | BridgeAndPrivateFlags | MACRO )
- }
-
- protected def isJavaEntryPoint(icls: IClass) = {
- val sym = icls.symbol
- def fail(msg: String, pos: Position = sym.pos) = {
- reporter.warning(sym.pos,
- sym.name + " has a main method with parameter type Array[String], but " + sym.fullName('.') + " will not be a runnable program.\n" +
- " Reason: " + msg
- // TODO: make this next claim true, if possible
- // by generating valid main methods as static in module classes
- // not sure what the jvm allows here
- // + " You can still run the program by calling it as " + sym.javaSimpleName + " instead."
- )
- false
- }
- def failNoForwarder(msg: String) = {
- fail(msg + ", which means no static forwarder can be generated.\n")
- }
- val possibles = if (sym.hasModuleFlag) (sym.tpe nonPrivateMember nme.main).alternatives else Nil
- val hasApproximate = possibles exists { m =>
- m.info match {
- case MethodType(p :: Nil, _) => p.tpe.typeSymbol == ArrayClass
- case _ => false
- }
- }
- // At this point it's a module with a main-looking method, so either succeed or warn that it isn't.
- hasApproximate && {
- // Before erasure so we can identify generic mains.
- enteringErasure {
- val companion = sym.linkedClassOfClass
-
- if (hasJavaMainMethod(companion))
- failNoForwarder("companion contains its own main method")
- else if (companion.tpe.member(nme.main) != NoSymbol)
- // this is only because forwarders aren't smart enough yet
- failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
- else if (companion.isTrait)
- failNoForwarder("companion is a trait")
- // Now either succeeed, or issue some additional warnings for things which look like
- // attempts to be java main methods.
- else (possibles exists isJavaMainMethod) || {
- possibles exists { m =>
- m.info match {
- case PolyType(_, _) =>
- fail("main methods cannot be generic.")
- case MethodType(params, res) =>
- if (res.typeSymbol :: params exists (_.isAbstractType))
- fail("main methods cannot refer to type parameters or abstract types.", m.pos)
- else
- isJavaMainMethod(m) || fail("main method must have exact signature (Array[String])Unit", m.pos)
- case tp =>
- fail("don't know what this is: " + tp, m.pos)
- }
- }
- }
- }
- }
- }
-}
diff --git a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
index 0b218b711c..5bf611a7b0 100644
--- a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
@@ -29,7 +29,7 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
case INFO => null
}
- private def clabel(severity: Severity): String = {
+ protected def clabel(severity: Severity): String = {
val label0 = label(severity)
if (label0 eq null) "" else label0 + ": "
}
diff --git a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
index 4727e6d867..060a24d8d4 100644
--- a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
@@ -35,7 +35,11 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings {
case s: AbsSettings => this.userSetSettings == s.userSetSettings
case _ => false
}
- override def toString() = "Settings {\n%s}\n" format (userSetSettings map (" " + _ + "\n")).mkString
+ override def toString() = {
+ val uss = userSetSettings
+ val indent = if (uss.nonEmpty) " " * 2 else ""
+ uss.mkString(f"Settings {%n$indent", f"%n$indent", f"%n}%n")
+ }
def toConciseString = userSetSettings.mkString("(", " ", ")")
def checkDependencies =
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index bbe21477cb..23611bb629 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -125,14 +125,26 @@ class MutableSettings(val errorFn: String => Unit)
case Some(cmd) => setter(cmd)(args)
}
- // if arg is of form -Xfoo:bar,baz,quux
- def parseColonArg(s: String): Option[List[String]] = {
- val (p, args) = StringOps.splitWhere(s, _ == ':', doDropIndex = true) getOrElse (return None)
-
- // any non-Nil return value means failure and we return s unmodified
- tryToSetIfExists(p, (args split ",").toList, (s: Setting) => s.tryToSetColon _)
+ // -Xfoo: clears Clearables
+ def clearIfExists(cmd: String): Option[List[String]] = lookupSetting(cmd) match {
+ case Some(c: Clearable) => c.clear() ; Some(Nil)
+ case Some(s) => s.errorAndValue(s"Missing argument to $cmd", None)
+ case None => None
}
+ // if arg is of form -Xfoo:bar,baz,quux
+ // the entire arg is consumed, so return None for failure
+ // any non-Nil return value means failure and we return s unmodified
+ def parseColonArg(s: String): Option[List[String]] =
+ if (s endsWith ":") {
+ clearIfExists(s.init)
+ } else {
+ for {
+ (p, args) <- StringOps.splitWhere(s, _ == ':', doDropIndex = true)
+ rest <- tryToSetIfExists(p, (args split ",").toList, (s: Setting) => s.tryToSetColon _)
+ } yield rest
+ }
+
// if arg is of form -Xfoo or -Xfoo bar (name = "-Xfoo")
def parseNormalArg(p: String, args: List[String]): Option[List[String]] =
tryToSetIfExists(p, args, (s: Setting) => s.tryToSet _)
@@ -532,6 +544,7 @@ class MutableSettings(val errorFn: String => Unit)
def prepend(s: String) = prependPath.value = join(s, prependPath.value)
def append(s: String) = appendPath.value = join(appendPath.value, s)
+ override def isDefault = super.isDefault && prependPath.isDefault && appendPath.isDefault
override def value = join(
prependPath.value,
super.value,
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 466e397dd7..850534f2cc 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -262,6 +262,8 @@ trait ScalaSettings extends AbsScalaSettings
val Yreifydebug = BooleanSetting("-Yreify-debug", "Trace reification.")
val Ytyperdebug = BooleanSetting("-Ytyper-debug", "Trace all type assignments.")
val Ypatmatdebug = BooleanSetting("-Ypatmat-debug", "Trace pattern matching translation.")
+ val YpatmatExhaustdepth = IntSetting("-Ypatmat-exhaust-depth", "off", 20, Some((10, Int.MaxValue)),
+ str => Some(if(str.equalsIgnoreCase("off")) Int.MaxValue else str.toInt))
val Yquasiquotedebug = BooleanSetting("-Yquasiquote-debug", "Trace quasiquote-related activities.")
// TODO 2.12 Remove
diff --git a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
index 12e7b23f48..835d338ab3 100644
--- a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
+++ b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
@@ -260,7 +260,7 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
val captureProxies2 = new LinkedHashMap[Symbol, TermSymbol]
captures foreach {capture =>
- val sym = lambdaClass.newVariable(capture.name.toTermName, capture.pos, SYNTHETIC)
+ val sym = lambdaClass.newVariable(unit.freshTermName(capture.name.toString + "$"), capture.pos, SYNTHETIC)
sym setInfo capture.info
captureProxies2 += ((capture, sym))
}
diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala
index fa53ef48b5..4662ef6224 100644
--- a/src/compiler/scala/tools/nsc/transform/Flatten.scala
+++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala
@@ -77,8 +77,11 @@ abstract class Flatten extends InfoTransform {
if (sym.isTerm && !sym.isStaticModule) {
decls1 enter sym
if (sym.isModule) {
- // Nested, non-static moduls are transformed to methods.
- assert(sym.isMethod, s"Non-static $sym should have the lateMETHOD flag from RefChecks")
+ // In theory, we could assert(sym.isMethod), because nested, non-static moduls are
+ // transformed to methods (lateMETHOD flag added in RefChecks). But this requires
+ // forcing sym.info (see comment on isModuleNotMethod), which forces stub symbols
+ // too eagerly (SI-8907).
+
// Note that module classes are not entered into the 'decls' of the ClassInfoType
// of the outer class, only the module symbols are. So the current loop does
// not visit module classes. Therefore we set the LIFTED flag here for module
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
index 0899507bab..e6ddf8b758 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
@@ -10,7 +10,6 @@ package tools.nsc.transform.patmat
import scala.language.postfixOps
import scala.collection.mutable
import scala.reflect.internal.util.Statistics
-import scala.reflect.internal.util.Position
import scala.reflect.internal.util.HashSet
trait Logic extends Debugging {
@@ -72,6 +71,8 @@ trait Logic extends Debugging {
def unapply(v: Var): Some[Tree]
}
+ def reportWarning(message: String): Unit
+
// resets hash consing -- only supposed to be called by TreeMakersToProps
def prepareNewAnalysis(): Unit
@@ -86,7 +87,7 @@ trait Logic extends Debugging {
def mayBeNull: Boolean
// compute the domain and return it (call registerNull first!)
- def domainSyms: Option[mutable.LinkedHashSet[Sym]]
+ def domainSyms: Option[Set[Sym]]
// the symbol for this variable being equal to its statically known type
// (only available if registerEquality has been called for that type before)
@@ -204,7 +205,7 @@ trait Logic extends Debugging {
def removeVarEq(props: List[Prop], modelNull: Boolean = false): (Formula, List[Formula]) = {
val start = if (Statistics.canEnable) Statistics.startTimer(patmatAnaVarEq) else null
- val vars = mutable.LinkedHashSet[Var]()
+ val vars = new mutable.HashSet[Var]
object gatherEqualities extends PropTraverser {
override def apply(p: Prop) = p match {
@@ -291,7 +292,7 @@ trait Logic extends Debugging {
def eqFreePropToSolvable(p: Prop): Formula
def cnfString(f: Formula): String
- type Model = collection.immutable.SortedMap[Sym, Boolean]
+ type Model = Map[Sym, Boolean]
val EmptyModel: Model
val NoModel: Model
@@ -341,9 +342,9 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
// we enumerate the subtypes of the full type, as that allows us to filter out more types statically,
// once we go to run-time checks (on Const's), convert them to checkable types
// TODO: there seems to be bug for singleton domains (variable does not show up in model)
- lazy val domain: Option[mutable.LinkedHashSet[Const]] = {
- val subConsts: Option[mutable.LinkedHashSet[Const]] = enumerateSubtypes(staticTp).map { tps =>
- mutable.LinkedHashSet(tps: _*).map{ tp =>
+ lazy val domain: Option[Set[Const]] = {
+ val subConsts = enumerateSubtypes(staticTp).map{ tps =>
+ tps.toSet[Type].map{ tp =>
val domainC = TypeConst(tp)
registerEquality(domainC)
domainC
@@ -486,7 +487,7 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
}
// accessing after calling registerNull will result in inconsistencies
- lazy val domainSyms: Option[collection.mutable.LinkedHashSet[Sym]] = domain map { _ map symForEqualsTo }
+ lazy val domainSyms: Option[Set[Sym]] = domain map { _ map symForEqualsTo }
lazy val symForStaticTp: Option[Sym] = symForEqualsTo.get(TypeConst(staticTpCheckable))
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala
index b2dc6e4e52..21e90b1d78 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala
@@ -9,7 +9,6 @@ package scala.tools.nsc.transform.patmat
import scala.language.postfixOps
import scala.collection.mutable
import scala.reflect.internal.util.Statistics
-import scala.reflect.internal.util.Position
trait TreeAndTypeAnalysis extends Debugging {
import global._
@@ -173,7 +172,6 @@ trait TreeAndTypeAnalysis extends Debugging {
// a type is "uncheckable" (for exhaustivity) if we don't statically know its subtypes (i.e., it's unsealed)
// we consider tuple types with at least one component of a checkable type as a checkable type
def uncheckableType(tp: Type): Boolean = {
- def tupleComponents(tp: Type) = tp.normalize.typeArgs
val checkable = (
(isTupleType(tp) && tupleComponents(tp).exists(tp => !uncheckableType(tp)))
|| enumerateSubtypes(tp).nonEmpty)
@@ -400,6 +398,7 @@ trait MatchAnalysis extends MatchApproximation {
trait MatchAnalyzer extends MatchApproximator {
def uncheckedWarning(pos: Position, msg: String) = currentRun.reporting.uncheckedWarning(pos, msg)
def warn(pos: Position, ex: AnalysisBudget.Exception, kind: String) = uncheckedWarning(pos, s"Cannot check match for $kind.\n${ex.advice}")
+ def reportWarning(message: String) = global.reporter.warning(typer.context.tree.pos, message)
// TODO: model dependencies between variables: if V1 corresponds to (x: List[_]) and V2 is (x.hd), V2 cannot be assigned when V1 = null or V1 = Nil
// right now hackily implement this by pruning counter-examples
@@ -524,9 +523,11 @@ trait MatchAnalysis extends MatchApproximation {
val matchFailModels = findAllModelsFor(propToSolvable(matchFails))
val scrutVar = Var(prevBinderTree)
- val counterExamples = matchFailModels.map(modelToCounterExample(scrutVar))
-
- val pruned = CounterExample.prune(counterExamples).map(_.toString).sorted
+ val counterExamples = matchFailModels.flatMap(modelToCounterExample(scrutVar))
+ // sorting before pruning is important here in order to
+ // keep neg/t7020.scala stable
+ // since e.g. List(_, _) would cover List(1, _)
+ val pruned = CounterExample.prune(counterExamples.sortBy(_.toString)).map(_.toString)
if (Statistics.canEnable) Statistics.stopTimer(patmatAnaExhaust, start)
pruned
@@ -616,7 +617,7 @@ trait MatchAnalysis extends MatchApproximation {
// (the variables don't take into account type information derived from other variables,
// so, naively, you might try to construct a counter example like _ :: Nil(_ :: _, _ :: _),
// since we didn't realize the tail of the outer cons was a Nil)
- def modelToCounterExample(scrutVar: Var)(model: Model): CounterExample = {
+ def modelToCounterExample(scrutVar: Var)(model: Model): Option[CounterExample] = {
// x1 = ...
// x1.hd = ...
// x1.tl = ...
@@ -674,6 +675,7 @@ trait MatchAnalysis extends MatchApproximation {
private val fields: mutable.Map[Symbol, VariableAssignment] = mutable.HashMap.empty
// need to prune since the model now incorporates all super types of a constant (needed for reachability)
private lazy val uniqueEqualTo = equalTo filterNot (subsumed => equalTo.exists(better => (better ne subsumed) && instanceOfTpImplies(better.tp, subsumed.tp)))
+ private lazy val inSameDomain = uniqueEqualTo forall (const => variable.domainSyms.exists(_.exists(_.const.tp =:= const.tp)))
private lazy val prunedEqualTo = uniqueEqualTo filterNot (subsumed => variable.staticTpCheckable <:< subsumed.tp)
private lazy val ctor = (prunedEqualTo match { case List(TypeConst(tp)) => tp case _ => variable.staticTpCheckable }).typeSymbol.primaryConstructor
private lazy val ctorParams = if (ctor.paramss.isEmpty) Nil else ctor.paramss.head
@@ -694,13 +696,13 @@ trait MatchAnalysis extends MatchApproximation {
// NoExample if the constructor call is ill-typed
// (thus statically impossible -- can we incorporate this into the formula?)
// beBrief is used to suppress negative information nested in tuples -- it tends to get too noisy
- def toCounterExample(beBrief: Boolean = false): CounterExample =
- if (!allFieldAssignmentsLegal) NoExample
+ def toCounterExample(beBrief: Boolean = false): Option[CounterExample] =
+ if (!allFieldAssignmentsLegal) Some(NoExample)
else {
debug.patmat("describing "+ ((variable, equalTo, notEqualTo, fields, cls, allFieldAssignmentsLegal)))
val res = prunedEqualTo match {
// a definite assignment to a value
- case List(eq: ValueConst) if fields.isEmpty => ValueExample(eq)
+ case List(eq: ValueConst) if fields.isEmpty => Some(ValueExample(eq))
// constructor call
// or we did not gather any information about equality but we have information about the fields
@@ -713,30 +715,50 @@ trait MatchAnalysis extends MatchApproximation {
// figure out the constructor arguments from the field assignment
val argLen = (caseFieldAccs.length min ctorParams.length)
- (0 until argLen).map(i => fields.get(caseFieldAccs(i)).map(_.toCounterExample(brevity)) getOrElse WildcardExample).toList
+ val examples = (0 until argLen).map(i => fields.get(caseFieldAccs(i)).map(_.toCounterExample(brevity)) getOrElse Some(WildcardExample)).toList
+ sequence(examples)
}
cls match {
- case ConsClass => ListExample(args())
- case _ if isTupleSymbol(cls) => TupleExample(args(brevity = true))
- case _ => ConstructorExample(cls, args())
+ case ConsClass =>
+ args().map {
+ case List(NoExample, l: ListExample) =>
+ // special case for neg/t7020.scala:
+ // if we find a counter example `??::*` we report `*::*` instead
+ // since the `??` originates from uniqueEqualTo containing several instanced of the same type
+ List(WildcardExample, l)
+ case args => args
+ }.map(ListExample)
+ case _ if isTupleSymbol(cls) => args(brevity = true).map(TupleExample)
+ case _ if cls.isSealed && cls.isAbstractClass =>
+ // don't report sealed abstract classes, since
+ // 1) they can't be instantiated
+ // 2) we are already reporting any missing subclass (since we know the full domain)
+ // (see patmatexhaust.scala)
+ None
+ case _ => args().map(ConstructorExample(cls, _))
}
// a definite assignment to a type
- case List(eq) if fields.isEmpty => TypeExample(eq)
+ case List(eq) if fields.isEmpty => Some(TypeExample(eq))
// negative information
case Nil if nonTrivialNonEqualTo.nonEmpty =>
// negation tends to get pretty verbose
- if (beBrief) WildcardExample
+ if (beBrief) Some(WildcardExample)
else {
val eqTo = equalTo.headOption getOrElse TypeConst(variable.staticTpCheckable)
- NegativeExample(eqTo, nonTrivialNonEqualTo)
+ Some(NegativeExample(eqTo, nonTrivialNonEqualTo))
}
+ // if uniqueEqualTo contains more than one symbol of the same domain
+ // then we can safely ignore these counter examples since we will eventually encounter
+ // both counter examples separately
+ case _ if inSameDomain => None
+
// not a valid counter-example, possibly since we have a definite type but there was a field mismatch
// TODO: improve reasoning -- in the mean time, a false negative is better than an annoying false positive
- case _ => NoExample
+ case _ => Some(NoExample)
}
debug.patmatResult("described as")(res)
}
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
index 1974befb45..3abec521df 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
@@ -550,8 +550,24 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
case _ => false
}
val suppression = Suppression(suppressExhaustive, supressUnreachable)
+ val hasSwitchAnnotation = treeInfo.isSwitchAnnotation(tpt.tpe)
// matches with two or fewer cases need not apply for switchiness (if-then-else will do)
- val requireSwitch = treeInfo.isSwitchAnnotation(tpt.tpe) && casesNoSubstOnly.lengthCompare(2) > 0
+ // `case 1 | 2` is considered as two cases.
+ def exceedsTwoCasesOrAlts = {
+ // avoids traversing the entire list if there are more than 3 elements
+ def lengthMax3[T](l: List[T]): Int = l match {
+ case a :: b :: c :: _ => 3
+ case cases =>
+ cases.map({
+ case AlternativesTreeMaker(_, alts, _) :: _ => lengthMax3(alts)
+ case c => 1
+ }).sum
+ }
+ lengthMax3(casesNoSubstOnly) > 2
+ }
+ val requireSwitch = hasSwitchAnnotation && exceedsTwoCasesOrAlts
+ if (hasSwitchAnnotation && !requireSwitch)
+ reporter.warning(scrut.pos, "matches with two cases or fewer are emitted using if-then-else instead of switch")
(suppression, requireSwitch)
case _ =>
(Suppression.NoSuppression, false)
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala b/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala
index 31b1ffa912..4330781013 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala
@@ -26,16 +26,9 @@ trait Solving extends Logic {
type Formula = FormulaBuilder
def formula(c: Clause*): Formula = ArrayBuffer(c: _*)
- type Clause = collection.Set[Lit]
+ type Clause = Set[Lit]
// a clause is a disjunction of distinct literals
- def clause(l: Lit*): Clause = (
- if (l.lengthCompare(1) <= 0) {
- l.toSet // SI-8531 Avoid LinkedHashSet's bulk for 0 and 1 element clauses
- } else {
- // neg/t7020.scala changes output 1% of the time, the non-determinism is quelled with this linked set
- mutable.LinkedHashSet(l: _*)
- }
- )
+ def clause(l: Lit*): Clause = l.toSet
type Lit
def Lit(sym: Sym, pos: Boolean = true): Lit
@@ -115,7 +108,6 @@ trait Solving extends Logic {
if (Statistics.canEnable) Statistics.stopTimer(patmatCNF, start)
- //
if (Statistics.canEnable) patmatCNFSizes(res.size).value += 1
// debug.patmat("cnf for\n"+ p +"\nis:\n"+cnfString(res))
@@ -141,36 +133,83 @@ trait Solving extends Logic {
def cnfString(f: Formula) = alignAcrossRows(f map (_.toList) toList, "\\/", " /\\\n")
// adapted from http://lara.epfl.ch/w/sav10:simple_sat_solver (original by Hossein Hojjat)
- val EmptyModel = collection.immutable.SortedMap.empty[Sym, Boolean]
+ val EmptyModel = Map.empty[Sym, Boolean]
val NoModel: Model = null
// returns all solutions, if any (TODO: better infinite recursion backstop -- detect fixpoint??)
def findAllModelsFor(f: Formula): List[Model] = {
+
+ debug.patmat("find all models for\n"+ cnfString(f))
+
val vars: Set[Sym] = f.flatMap(_ collect {case l: Lit => l.sym}).toSet
// debug.patmat("vars "+ vars)
// the negation of a model -(S1=True/False /\ ... /\ SN=True/False) = clause(S1=False/True, ...., SN=False/True)
def negateModel(m: Model) = clause(m.toSeq.map{ case (sym, pos) => Lit(sym, !pos) } : _*)
- def findAllModels(f: Formula, models: List[Model], recursionDepthAllowed: Int = 10): List[Model]=
- if (recursionDepthAllowed == 0) models
- else {
- debug.patmat("find all models for\n"+ cnfString(f))
+ /**
+ * The DPLL procedure only returns a minimal mapping from literal to value
+ * such that the CNF formula is satisfied.
+ * E.g. for:
+ * `(a \/ b)`
+ * The DPLL procedure will find either {a = true} or {b = true}
+ * as solution.
+ *
+ * The expansion step will amend both solutions with the unassigned variable
+ * i.e., {a = true} will be expanded to {a = true, b = true} and {a = true, b = false}.
+ */
+ def expandUnassigned(unassigned: List[Sym], model: Model): List[Model] = {
+ // the number of solutions is doubled for every unassigned variable
+ val expandedModels = 1 << unassigned.size
+ var current = mutable.ArrayBuffer[Model]()
+ var next = mutable.ArrayBuffer[Model]()
+ current.sizeHint(expandedModels)
+ next.sizeHint(expandedModels)
+
+ current += model
+
+ // we use double buffering:
+ // read from `current` and create a two models for each model in `next`
+ for {
+ s <- unassigned
+ } {
+ for {
+ model <- current
+ } {
+ def force(l: Lit) = model + (l.sym -> l.pos)
+
+ next += force(Lit(s, pos = true))
+ next += force(Lit(s, pos = false))
+ }
+
+ val tmp = current
+ current = next
+ next = tmp
+
+ next.clear()
+ }
+
+ current.toList
+ }
+
+ def findAllModels(f: Formula,
+ models: List[Model],
+ recursionDepthAllowed: Int = global.settings.YpatmatExhaustdepth.value): List[Model]=
+ if (recursionDepthAllowed == 0) {
+ val maxDPLLdepth = global.settings.YpatmatExhaustdepth.value
+ reportWarning("(Exhaustivity analysis reached max recursion depth, not all missing cases are reported. " +
+ s"Please try with scalac -Ypatmat-exhaust-depth ${maxDPLLdepth * 2} or -Ypatmat-exhaust-depth off.)")
+ models
+ } else {
val model = findModelFor(f)
// if we found a solution, conjunct the formula with the model's negation and recurse
if (model ne NoModel) {
val unassigned = (vars -- model.keySet).toList
debug.patmat("unassigned "+ unassigned +" in "+ model)
- def force(lit: Lit) = {
- val model = withLit(findModelFor(dropUnit(f, lit)), lit)
- if (model ne NoModel) List(model)
- else Nil
- }
- val forced = unassigned flatMap { s =>
- force(Lit(s, pos = true)) ++ force(Lit(s, pos = false))
- }
+
+ val forced = expandUnassigned(unassigned, model)
debug.patmat("forced "+ forced)
val negated = negateModel(model)
- findAllModels(f :+ negated, model :: (forced ++ models), recursionDepthAllowed - 1)
+ findAllModels(f :+ negated, forced ++ models, recursionDepthAllowed - 1)
}
else models
}
@@ -210,15 +249,14 @@ trait Solving extends Logic {
withLit(findModelFor(dropUnit(f, unitLit)), unitLit)
case _ =>
// partition symbols according to whether they appear in positive and/or negative literals
- // SI-7020 Linked- for deterministic counter examples.
- val pos = new mutable.LinkedHashSet[Sym]()
- val neg = new mutable.LinkedHashSet[Sym]()
+ val pos = new mutable.HashSet[Sym]()
+ val neg = new mutable.HashSet[Sym]()
mforeach(f)(lit => if (lit.pos) pos += lit.sym else neg += lit.sym)
// appearing in both positive and negative
- val impures: mutable.LinkedHashSet[Sym] = pos intersect neg
+ val impures = pos intersect neg
// appearing only in either positive/negative positions
- val pures: mutable.LinkedHashSet[Sym] = (pos ++ neg) -- impures
+ val pures = (pos ++ neg) -- impures
if (pures nonEmpty) {
val pureSym = pures.head
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
index 20e462bbce..866ca37303 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
@@ -885,22 +885,31 @@ trait ContextErrors {
val WrongNumber, NoParams, ArgsDoNotConform = Value
}
- private def issueAmbiguousTypeErrorUnlessErroneous(pos: Position, pre: Type, sym1: Symbol, sym2: Symbol, rest: String): Unit =
- if (!(pre.isErroneous || sym1.isErroneous || sym2.isErroneous)) {
- if (sym1.hasDefault && sym2.hasDefault && sym1.enclClass == sym2.enclClass) {
- val methodName = nme.defaultGetterToMethod(sym1.name)
- context.issueAmbiguousError(AmbiguousTypeError(sym1.enclClass.pos,
- "in "+ sym1.enclClass +", multiple overloaded alternatives of " + methodName +
- " define default arguments"))
- } else {
- context.issueAmbiguousError(AmbiguousTypeError(pos,
- ("ambiguous reference to overloaded definition,\n" +
- "both " + sym1 + sym1.locationString + " of type " + pre.memberType(sym1) +
- "\nand " + sym2 + sym2.locationString + " of type " + pre.memberType(sym2) +
- "\nmatch " + rest)
- ))
- }
- }
+ private def issueAmbiguousTypeErrorUnlessErroneous(pos: Position, pre: Type, sym1: Symbol, sym2: Symbol, rest: String): Unit = {
+ // To avoid stack overflows (SI-8890), we MUST (at least) report when either `validTargets` OR `ambiguousSuppressed`
+ // More details:
+ // If `!context.ambiguousErrors`, `reporter.issueAmbiguousError` (which `context.issueAmbiguousError` forwards to)
+ // buffers ambiguous errors. In this case, to avoid looping, we must issue even if `!validTargets`. (TODO: why?)
+ // When not buffering (and thus reporting to the user), we shouldn't issue unless `validTargets`,
+ // otherwise we report two different errors that trace back to the same root cause,
+ // and unless `validTargets`, we don't know for sure the ambiguity is real anyway.
+ val validTargets = !(pre.isErroneous || sym1.isErroneous || sym2.isErroneous)
+ val ambiguousBuffered = !context.ambiguousErrors
+ if (validTargets || ambiguousBuffered)
+ context.issueAmbiguousError(
+ if (sym1.hasDefault && sym2.hasDefault && sym1.enclClass == sym2.enclClass) {
+ val methodName = nme.defaultGetterToMethod(sym1.name)
+ AmbiguousTypeError(sym1.enclClass.pos,
+ s"in ${sym1.enclClass}, multiple overloaded alternatives of $methodName define default arguments")
+
+ } else {
+ AmbiguousTypeError(pos,
+ "ambiguous reference to overloaded definition,\n" +
+ s"both ${sym1.fullLocationString} of type ${pre.memberType(sym1)}\n" +
+ s"and ${sym2.fullLocationString} of type ${pre.memberType(sym2)}\n" +
+ s"match $rest")
+ })
+ }
def AccessError(tree: Tree, sym: Symbol, ctx: Context, explanation: String): AbsTypeError =
AccessError(tree, sym, ctx.enclClass.owner.thisType, ctx.enclClass.owner, explanation)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index c86eaffccf..da0ae4ee79 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -480,6 +480,8 @@ trait Contexts { self: Analyzer =>
// SI-8245 `isLazy` need to skip lazy getters to ensure `return` binds to the right place
c.enclMethod = if (isDefDef && !owner.isLazy) c else enclMethod
+ if (tree != outer.tree) c(TypeConstructorAllowed) = false
+
registerContext(c.asInstanceOf[analyzer.Context])
debuglog("[context] ++ " + c.unit + " / " + tree.summaryString)
c
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index e2ad578252..7ed4fe1f88 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -1475,8 +1475,10 @@ trait Implicits {
})
private lazy val typeParamNames: List[String] = sym.typeParams.map(_.decodedName)
+ private def typeArgsAtSym(paramTp: Type) = paramTp.baseType(sym).typeArgs
+
+ def format(paramName: Name, paramTp: Type): String = format(typeArgsAtSym(paramTp) map (_.toString))
- def format(paramName: Name, paramTp: Type): String = format(paramTp.typeArgs map (_.toString))
def format(typeArgs: List[String]): String =
interpolate(msg, Map((typeParamNames zip typeArgs): _*)) // TODO: give access to the name and type of the implicit argument, etc?
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index fdff2f3076..e876d4a6af 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -1643,6 +1643,7 @@ trait Namers extends MethodSynthesis {
def symbolAllowsDeferred = (
sym.isValueParameter
|| sym.isTypeParameterOrSkolem
+ || (sym.isAbstractType && sym.owner.isClass)
|| context.tree.isInstanceOf[ExistentialTypeTree]
)
// Does the symbol owner require no undefined members?
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index fe6038bc00..20db85e665 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1104,7 +1104,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
adaptConstant(value)
case OverloadedType(pre, alts) if !mode.inFunMode => // (1)
inferExprAlternative(tree, pt)
- adapt(tree, mode, pt, original)
+ adaptAfterOverloadResolution(tree, mode, pt, original)
case NullaryMethodType(restpe) => // (2)
adapt(tree setType restpe, mode, pt, original)
case TypeRef(_, ByNameParamClass, arg :: Nil) if mode.inExprMode => // (2)
@@ -1137,6 +1137,12 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
}
+ // This just exists to help keep track of the spots where we have to adapt a tree after
+ // overload resolution. These proved hard to find during the fix for SI-8267.
+ def adaptAfterOverloadResolution(tree: Tree, mode: Mode, pt: Type = WildcardType, original: Tree = EmptyTree): Tree = {
+ adapt(tree, mode, pt, original)
+ }
+
def instantiate(tree: Tree, mode: Mode, pt: Type): Tree = {
inferExprInstance(tree, context.extractUndetparams(), pt)
adapt(tree, mode, pt)
@@ -1724,7 +1730,10 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if ((clazz isNonBottomSubClass ClassfileAnnotationClass) && (clazz != ClassfileAnnotationClass)) {
if (!clazz.owner.isPackageClass)
context.error(clazz.pos, "inner classes cannot be classfile annotations")
- else restrictionWarning(cdef.pos, unit,
+ // Ignore @SerialVersionUID, because it is special-cased and handled completely differently.
+ // It only extends ClassfileAnnotationClass instead of StaticAnnotation to get the enforcement
+ // of constant argument values "for free". Related to SI-7041.
+ else if (clazz != SerialVersionUIDAttr) restrictionWarning(cdef.pos, unit,
"""|subclassing Classfile does not
|make your annotation visible at runtime. If that is what
|you want, you must write the annotation class in Java.""".stripMargin)
@@ -3175,7 +3184,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
if (sym1 != NoSymbol) sym = sym1
}
if (sym == NoSymbol) fun
- else adapt(fun setSymbol sym setType pre.memberType(sym), mode.forFunMode, WildcardType)
+ else adaptAfterOverloadResolution(fun setSymbol sym setType pre.memberType(sym), mode.forFunMode)
} else fun
}
@@ -3220,7 +3229,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
setError(tree)
else {
inferMethodAlternative(fun, undetparams, argTpes, pt)
- doTypedApply(tree, adapt(fun, mode.forFunMode, WildcardType), args1, mode, pt)
+ doTypedApply(tree, adaptAfterOverloadResolution(fun, mode.forFunMode, WildcardType), args1, mode, pt)
}
}
handleOverloaded
@@ -3803,7 +3812,18 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
protected def typedTypeApply(tree: Tree, mode: Mode, fun: Tree, args: List[Tree]): Tree = fun.tpe match {
case OverloadedType(pre, alts) =>
inferPolyAlternatives(fun, mapList(args)(treeTpe))
- val tparams = fun.symbol.typeParams //@M TODO: fun.symbol.info.typeParams ? (as in typedAppliedTypeTree)
+
+ // SI-8267 `memberType` can introduce existentials *around* a PolyType/MethodType, see AsSeenFromMap#captureThis.
+ // If we had selected a non-overloaded symbol, `memberType` would have been called in `makeAccessible`
+ // and the resulting existential type would have been skolemized in `adapt` *before* we typechecked
+ // the enclosing type-/ value- application.
+ //
+ // However, if the selection is overloaded, we defer calling `memberType` until we can select a single
+ // alternative here. It is therefore necessary to skolemize the existential here.
+ //
+ val fun1 = adaptAfterOverloadResolution(fun, mode.forFunMode | TAPPmode)
+
+ val tparams = fun1.symbol.typeParams //@M TODO: fun.symbol.info.typeParams ? (as in typedAppliedTypeTree)
val args1 = if (sameLength(args, tparams)) {
//@M: in case TypeApply we can't check the kind-arities of the type arguments,
// as we don't know which alternative to choose... here we do
@@ -3817,7 +3837,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// ...actually this was looping anyway, see bug #278.
return TypedApplyWrongNumberOfTpeParametersError(fun, fun)
- typedTypeApply(tree, mode, fun, args1)
+ typedTypeApply(tree, mode, fun1, args1)
case SingleType(_, _) =>
typedTypeApply(tree, mode, fun setType fun.tpe.widen, args)
case PolyType(tparams, restpe) if tparams.nonEmpty =>
diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala
index 9fa877055f..0b380517f8 100644
--- a/src/library/scala/collection/immutable/Range.scala
+++ b/src/library/scala/collection/immutable/Range.scala
@@ -33,7 +33,13 @@ import scala.collection.parallel.immutable.ParRange
* `init`) are also permitted on overfull ranges.
*
* @param start the start of this range.
- * @param end the exclusive end of the range.
+ * @param end the end of the range. For exclusive ranges, e.g.
+ * `Range(0,3)` or `(0 until 3)`, this is one
+ * step past the last one in the range. For inclusive
+ * ranges, e.g. `Range.inclusive(0,3)` or `(0 to 3)`,
+ * it may be in the range if it is not skipped by the step size.
+ * To find the last element inside a non-empty range,
+ use `last` instead.
* @param step the step for the range.
*
* @author Martin Odersky
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index 738b294ce6..bf93a38f55 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -135,23 +135,29 @@ self =>
def linesIterator: Iterator[String] =
linesWithSeparators map (line => new WrappedString(line).stripLineEnd)
- /** Returns this string with first character converted to upper case */
+ /** Returns this string with first character converted to upper case.
+ * If the first character of the string is capitalized, it is returned unchanged.
+ */
def capitalize: String =
if (toString == null) null
else if (toString.length == 0) ""
+ else if (toString.charAt(0).isUpper) toString
else {
val chars = toString.toCharArray
chars(0) = chars(0).toUpper
new String(chars)
}
- /** Returns this string with the given `prefix` stripped. */
+ /** Returns this string with the given `prefix` stripped. If this string does not
+ * start with `prefix`, it is returned unchanged.
+ */
def stripPrefix(prefix: String) =
if (toString.startsWith(prefix)) toString.substring(prefix.length)
else toString
/** Returns this string with the given `suffix` stripped. If this string does not
- * end with `suffix`, it is returned unchanged. */
+ * end with `suffix`, it is returned unchanged.
+ */
def stripSuffix(suffix: String) =
if (toString.endsWith(suffix)) toString.substring(0, toString.length() - suffix.length)
else toString
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala
index b949bec48a..a6e538528a 100644
--- a/src/library/scala/collection/mutable/PriorityQueue.scala
+++ b/src/library/scala/collection/mutable/PriorityQueue.scala
@@ -16,6 +16,11 @@ import generic._
* To prioritize elements of type A there must be an implicit
* Ordering[A] available at creation.
*
+ * Only the `dequeue` and `dequeueAll` methods will return methods in priority
+ * order (while removing elements from the heap). Standard collection methods
+ * including `drop` and `iterator` will remove or traverse the heap in whichever
+ * order seems most convenient.
+ *
* @tparam A type of the elements in this priority queue.
* @param ord implicit ordering used to compare the elements of type `A`.
*
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 02578e2038..70375d974c 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -653,6 +653,7 @@ trait Definitions extends api.StandardDefinitions {
// tends to change the course of events by forcing types.
def isFunctionType(tp: Type) = isFunctionTypeDirect(tp.dealiasWiden)
def isTupleType(tp: Type) = isTupleTypeDirect(tp.dealiasWiden)
+ def tupleComponents(tp: Type) = tp.dealiasWiden.typeArgs
lazy val ProductRootClass: ClassSymbol = requiredClass[scala.Product]
def Product_productArity = getMemberMethod(ProductRootClass, nme.productArity)
@@ -837,7 +838,7 @@ trait Definitions extends api.StandardDefinitions {
def typeOfMemberNamedApply(tp: Type) = typeArgOfBaseTypeOr(tp, SeqClass)(resultOfMatchingMethod(tp, nme.apply)(IntTpe))
def typeOfMemberNamedDrop(tp: Type) = typeArgOfBaseTypeOr(tp, SeqClass)(resultOfMatchingMethod(tp, nme.drop)(IntTpe))
def typesOfSelectors(tp: Type) =
- if (isTupleType(tp)) tp.typeArgs
+ if (isTupleType(tp)) tupleComponents(tp)
else getterMemberTypes(tp, productSelectors(tp))
// SI-8128 Still using the type argument of the base type at Seq/Option if this is an old-style (2.10 compatible)
@@ -1087,6 +1088,10 @@ trait Definitions extends api.StandardDefinitions {
lazy val ClassfileAnnotationClass = requiredClass[scala.annotation.ClassfileAnnotation]
lazy val StaticAnnotationClass = requiredClass[scala.annotation.StaticAnnotation]
+ // Java retention annotations
+ lazy val AnnotationRetentionAttr = requiredClass[java.lang.annotation.Retention]
+ lazy val AnnotationRetentionPolicyAttr = requiredClass[java.lang.annotation.RetentionPolicy]
+
// Annotations
lazy val BridgeClass = requiredClass[scala.annotation.bridge]
lazy val ElidableMethodClass = requiredClass[scala.annotation.elidable]
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index e65c55885e..aa62df7093 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -735,31 +735,31 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def hasGetter = isTerm && nme.isLocalName(name)
- /** A little explanation for this confusing situation.
- * Nested modules which have no static owner when ModuleDefs
- * are eliminated (refchecks) are given the lateMETHOD flag,
- * which makes them appear as methods after refchecks.
- * Here's an example where one can see all four of FF FT TF TT
- * for (isStatic, isMethod) at various phases.
+ /**
+ * Nested modules which have no static owner when ModuleDefs are eliminated (refchecks) are
+ * given the lateMETHOD flag, which makes them appear as methods after refchecks.
+ *
+ * Note: the lateMETHOD flag is added lazily in the info transformer of the RefChecks phase.
+ * This means that forcing the `sym.info` may change the value of `sym.isMethod`. Forcing the
+ * info is in the responsability of the caller. Doing it eagerly here was tried (0ccdb151f) but
+ * has proven to lead to bugs (SI-8907).
*
- * trait A1 { case class Quux() }
- * object A2 extends A1 { object Flax }
- * // -- namer object Quux in trait A1
- * // -M flatten object Quux in trait A1
- * // S- flatten object Flax in object A2
- * // -M posterasure object Quux in trait A1
- * // -M jvm object Quux in trait A1
- * // SM jvm object Quux in object A2
+ * Here's an example where one can see all four of FF FT TF TT for (isStatic, isMethod) at
+ * various phases.
*
- * So "isModuleNotMethod" exists not for its achievement in
- * brevity, but to encapsulate the relevant condition.
+ * trait A1 { case class Quux() }
+ * object A2 extends A1 { object Flax }
+ * // -- namer object Quux in trait A1
+ * // -M flatten object Quux in trait A1
+ * // S- flatten object Flax in object A2
+ * // -M posterasure object Quux in trait A1
+ * // -M jvm object Quux in trait A1
+ * // SM jvm object Quux in object A2
+ *
+ * So "isModuleNotMethod" exists not for its achievement in brevity, but to encapsulate the
+ * relevant condition.
*/
- def isModuleNotMethod = {
- if (isModule) {
- if (phase.refChecked) this.info // force completion to make sure lateMETHOD is there.
- !isMethod
- } else false
- }
+ def isModuleNotMethod = isModule && !isMethod
// After RefChecks, the `isStatic` check is mostly redundant: all non-static modules should
// be methods (and vice versa). There's a corner case on the vice-versa with mixed-in module
@@ -2029,12 +2029,19 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
info.decls.filter(sym => !sym.isMethod && sym.isParamAccessor).toList
/** The symbol accessed by this accessor (getter or setter) function. */
- final def accessed: Symbol = accessed(owner.info)
-
- /** The symbol accessed by this accessor function, but with given owner type. */
- final def accessed(ownerTp: Type): Symbol = {
+ final def accessed: Symbol = {
assert(hasAccessorFlag, this)
- ownerTp decl localName
+ val localField = owner.info decl localName
+
+ if (localField == NoSymbol && this.hasFlag(MIXEDIN)) {
+ // SI-8087: private[this] fields don't have a `localName`. When searching the accessed field
+ // for a mixin accessor of such a field, we need to look for `name` instead.
+ // The phase travel ensures that the field is found (`owner` is the trait class symbol, the
+ // field gets removed from there in later phases).
+ enteringPhase(picklerPhase)(owner.info).decl(name).suchThat(!_.isAccessor)
+ } else {
+ localField
+ }
}
/** The module corresponding to this module class (note that this
diff --git a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
index 8d4c3f752f..5433bfad60 100644
--- a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
@@ -243,8 +243,14 @@ abstract class UnPickler {
} getOrElse "")
}
+ def localDummy = {
+ if (nme.isLocalDummyName(name))
+ owner.newLocalDummy(NoPosition)
+ else NoSymbol
+ }
+
// (1) Try name.
- fromName(name) orElse {
+ localDummy orElse fromName(name) orElse {
// (2) Try with expanded name. Can happen if references to private
// symbols are read from outside: for instance when checking the children
// of a class. See #1722.
@@ -298,6 +304,7 @@ abstract class UnPickler {
* (.) ...
* (1) `local child` represents local child classes, see comment in Pickler.putSymbol.
* Since it is not a member, it should not be entered in the owner's scope.
+ * (2) Similarly, we ignore local dummy symbols, as seen in SI-8868
*/
def shouldEnterInOwnerScope = {
sym.owner.isClass &&
@@ -307,7 +314,8 @@ abstract class UnPickler {
!sym.isRefinementClass &&
!sym.isTypeParameter &&
!sym.isExistentiallyBound &&
- sym.rawname != tpnme.LOCAL_CHILD // (1)
+ sym.rawname != tpnme.LOCAL_CHILD && // (1)
+ !nme.isLocalDummyName(sym.rawname) // (2)
}
markFlagsCompleted(sym)(mask = AllFlags)
diff --git a/src/reflect/scala/reflect/internal/util/AbstractFileClassLoader.scala b/src/reflect/scala/reflect/internal/util/AbstractFileClassLoader.scala
index 10a8b4c812..30dcbc21ca 100644
--- a/src/reflect/scala/reflect/internal/util/AbstractFileClassLoader.scala
+++ b/src/reflect/scala/reflect/internal/util/AbstractFileClassLoader.scala
@@ -5,16 +5,16 @@
package scala
package reflect.internal.util
-import scala.reflect.io.AbstractFile
+import scala.collection.{ mutable, immutable }
+import scala.reflect.io.{ AbstractFile, Streamable }
+import java.net.{ URL, URLConnection, URLStreamHandler }
import java.security.cert.Certificate
import java.security.{ ProtectionDomain, CodeSource }
-import java.net.{ URL, URLConnection, URLStreamHandler }
-import scala.collection.{ mutable, immutable }
+import java.util.{ Collections => JCollections, Enumeration => JEnumeration }
-/**
- * A class loader that loads files from a {@link scala.tools.nsc.io.AbstractFile}.
+/** A class loader that loads files from a {@link scala.tools.nsc.io.AbstractFile}.
*
- * @author Lex Spoon
+ * @author Lex Spoon
*/
class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
extends ClassLoader(parent)
@@ -22,7 +22,7 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
{
protected def classNameToPath(name: String): String =
if (name endsWith ".class") name
- else name.replace('.', '/') + ".class"
+ else s"${name.replace('.', '/')}.class"
protected def findAbstractFile(name: String): AbstractFile = {
var file: AbstractFile = root
@@ -56,35 +56,25 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
file
}
- // parent delegation in JCL uses getResource; so either add parent.getResAsStream
- // or implement findResource, which we do here as a study in scarlet (my complexion
- // after looking at CLs and URLs)
- override def findResource(name: String): URL = findAbstractFile(name) match {
+ override protected def findClass(name: String): Class[_] = {
+ val bytes = classBytes(name)
+ if (bytes.length == 0)
+ throw new ClassNotFoundException(name)
+ else
+ defineClass(name, bytes, 0, bytes.length, protectionDomain)
+ }
+ override protected def findResource(name: String): URL = findAbstractFile(name) match {
case null => null
- case file => new URL(null, "repldir:" + file.path, new URLStreamHandler {
+ case file => new URL(null, s"memory:${file.path}", new URLStreamHandler {
override def openConnection(url: URL): URLConnection = new URLConnection(url) {
- override def connect() { }
+ override def connect() = ()
override def getInputStream = file.input
}
})
}
-
- // this inverts delegation order: super.getResAsStr calls parent.getRes if we fail
- override def getResourceAsStream(name: String) = findAbstractFile(name) match {
- case null => super.getResourceAsStream(name)
- case file => file.input
- }
- // ScalaClassLoader.classBytes uses getResAsStream, so we'll try again before delegating
- override def classBytes(name: String): Array[Byte] = findAbstractFile(classNameToPath(name)) match {
- case null => super.classBytes(name)
- case file => file.toByteArray
- }
- override def findClass(name: String): Class[_] = {
- val bytes = classBytes(name)
- if (bytes.length == 0)
- throw new ClassNotFoundException(name)
- else
- defineClass(name, bytes, 0, bytes.length, protectionDomain)
+ override protected def findResources(name: String): JEnumeration[URL] = findResource(name) match {
+ case null => JCollections.enumeration(JCollections.emptyList[URL]) //JCollections.emptyEnumeration[URL]
+ case url => JCollections.enumeration(JCollections.singleton(url))
}
lazy val protectionDomain = {
@@ -106,15 +96,13 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
throw new UnsupportedOperationException()
}
- override def getPackage(name: String): Package = {
- findAbstractDir(name) match {
- case null => super.getPackage(name)
- case file => packages.getOrElseUpdate(name, {
- val ctor = classOf[Package].getDeclaredConstructor(classOf[String], classOf[String], classOf[String], classOf[String], classOf[String], classOf[String], classOf[String], classOf[URL], classOf[ClassLoader])
- ctor.setAccessible(true)
- ctor.newInstance(name, null, null, null, null, null, null, null, this)
- })
- }
+ override def getPackage(name: String): Package = findAbstractDir(name) match {
+ case null => super.getPackage(name)
+ case file => packages.getOrElseUpdate(name, {
+ val ctor = classOf[Package].getDeclaredConstructor(classOf[String], classOf[String], classOf[String], classOf[String], classOf[String], classOf[String], classOf[String], classOf[URL], classOf[ClassLoader])
+ ctor.setAccessible(true)
+ ctor.newInstance(name, null, null, null, null, null, null, null, this)
+ })
}
override def getPackages(): Array[Package] =
diff --git a/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala b/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala
index 63ea6e2c49..41011f6c6b 100644
--- a/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala
+++ b/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala
@@ -53,8 +53,10 @@ trait ScalaClassLoader extends JClassLoader {
}
/** An InputStream representing the given class name, or null if not found. */
- def classAsStream(className: String) =
- getResourceAsStream(className.replaceAll("""\.""", "/") + ".class")
+ def classAsStream(className: String) = getResourceAsStream {
+ if (className endsWith ".class") className
+ else s"${className.replace('.', '/')}.class" // classNameToPath
+ }
/** Run the main method of a class to be loaded by this classloader */
def run(objectName: String, arguments: Seq[String]) {
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index dcd262c288..18a3c5d63f 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -360,6 +360,8 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.AnnotationClass
definitions.ClassfileAnnotationClass
definitions.StaticAnnotationClass
+ definitions.AnnotationRetentionAttr
+ definitions.AnnotationRetentionPolicyAttr
definitions.BridgeClass
definitions.ElidableMethodClass
definitions.ImplicitNotFoundClass
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index 50c89f7442..6e18682494 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -75,6 +75,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
def history = in.history
// classpath entries added via :cp
+ @deprecated("Use reset, replay or require to update class path", since = "2.11")
var addedClasspath: String = ""
/** A reverse list of commands to replay if the user requests a :replay */
@@ -207,7 +208,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
/** Standard commands **/
lazy val standardCommands = List(
- cmd("cp", "<path>", "add a jar or directory to the classpath", addClasspath),
cmd("edit", "<id>|<line>", "edit history", editCommand),
cmd("help", "[command]", "print this summary or command-specific help", helpCommand),
historyCommand,
@@ -220,11 +220,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
cmd("paste", "[-raw] [path]", "enter paste mode or paste a file", pasteCommand),
nullary("power", "enable power user mode", powerCmd),
nullary("quit", "exit the interpreter", () => Result(keepRunning = false, None)),
- nullary("replay", "reset execution and replay all previous commands", replay),
- nullary("reset", "reset the repl to its initial state, forgetting all session entries", resetCommand),
+ cmd("replay", "[options]", "reset the repl and replay all previous commands", replayCommand),
+ //cmd("require", "<path>", "add a jar or directory to the classpath", require), // TODO
+ cmd("reset", "[options]", "reset the repl to its initial state, forgetting all session entries", resetCommand),
cmd("save", "<path>", "save replayable session to a file", saveCommand),
shCommand,
- cmd("settings", "[+|-]<options>", "+enable/-disable flags, set compiler options", changeSettings),
+ cmd("settings", "<options>", "update compiler options, if possible; see reset", changeSettings),
nullary("silent", "disable/enable automatic printing of results", verbosity),
cmd("type", "[-v] <expr>", "display the type of an expression without evaluating it", typeCommand),
cmd("kind", "[-v] <expr>", "display the kind of expression's type", kindCommand),
@@ -304,57 +305,23 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
intp.lastWarnings foreach { case (pos, msg) => intp.reporter.warning(pos, msg) }
}
- private def changeSettings(args: String): Result = {
- def showSettings() = {
- for (s <- settings.userSetSettings.toSeq.sorted) echo(s.toString)
- }
- def updateSettings() = {
- // put aside +flag options
- val (pluses, rest) = (args split "\\s+").toList partition (_.startsWith("+"))
- val tmps = new Settings
- val (ok, leftover) = tmps.processArguments(rest, processAll = true)
- if (!ok) echo("Bad settings request.")
- else if (leftover.nonEmpty) echo("Unprocessed settings.")
- else {
- // boolean flags set-by-user on tmp copy should be off, not on
- val offs = tmps.userSetSettings filter (_.isInstanceOf[Settings#BooleanSetting])
- val (minuses, nonbools) = rest partition (arg => offs exists (_ respondsTo arg))
- // update non-flags
- settings.processArguments(nonbools, processAll = true)
- // also snag multi-value options for clearing, e.g. -Ylog: and -language:
- for {
- s <- settings.userSetSettings
- if s.isInstanceOf[Settings#MultiStringSetting] || s.isInstanceOf[Settings#PhasesSetting]
- if nonbools exists (arg => arg.head == '-' && arg.last == ':' && (s respondsTo arg.init))
- } s match {
- case c: Clearable => c.clear()
- case _ =>
- }
- def update(bs: Seq[String], name: String=>String, setter: Settings#Setting=>Unit) = {
- for (b <- bs)
- settings.lookupSetting(name(b)) match {
- case Some(s) =>
- if (s.isInstanceOf[Settings#BooleanSetting]) setter(s)
- else echo(s"Not a boolean flag: $b")
- case _ =>
- echo(s"Not an option: $b")
- }
- }
- update(minuses, identity, _.tryToSetFromPropertyValue("false")) // turn off
- update(pluses, "-" + _.drop(1), _.tryToSet(Nil)) // turn on
- }
- }
- if (args.isEmpty) showSettings() else updateSettings()
+ private def changeSettings(line: String): Result = {
+ def showSettings() = for (s <- settings.userSetSettings.toSeq.sorted) echo(s.toString)
+ if (line.isEmpty) showSettings() else { updateSettings(line) ; () }
+ }
+ private def updateSettings(line: String) = {
+ val (ok, rest) = settings.processArguments(words(line), processAll = false)
+ ok && rest.isEmpty
}
private def javapCommand(line: String): Result = {
if (javap == null)
- ":javap unavailable, no tools.jar at %s. Set JDK_HOME.".format(jdkHome)
+ s":javap unavailable, no tools.jar at $jdkHome. Set JDK_HOME."
else if (line == "")
":javap [-lcsvp] [path1 path2 ...]"
else
javap(words(line)) foreach { res =>
- if (res.isError) return "Failed: " + res.value
+ if (res.isError) return s"Failed: ${res.value}"
else res.show()
}
}
@@ -428,7 +395,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
// return false if repl should exit
def processLine(line: String): Boolean = {
import scala.concurrent.duration._
- Await.ready(globalFuture, 60.seconds)
+ Await.ready(globalFuture, 10.minutes) // Long timeout here to avoid test failures under heavy load.
if (line eq null) {
// SI-4563: this means the console was properly interrupted (Ctrl+D usually)
@@ -445,8 +412,14 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
private def readOneLine() = {
+ import scala.io.AnsiColor.{ MAGENTA, RESET }
out.flush()
- in readLine prompt
+ in readLine (
+ if (replProps.colorOk)
+ MAGENTA + prompt + RESET
+ else
+ prompt
+ )
}
/** The main read-eval-print loop for the repl. It calls
@@ -472,8 +445,16 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
/** create a new interpreter and replay the given commands */
- def replay() {
- reset()
+ def replayCommand(line: String): Unit = {
+ def run(destructive: Boolean): Unit = {
+ if (destructive) createInterpreter() else reset()
+ replay()
+ }
+ if (line.isEmpty) run(destructive = false)
+ else if (updateSettings(line)) run(destructive = true)
+ }
+ /** Announces as it replays. */
+ def replay(): Unit = {
if (replayCommandStack.isEmpty)
echo("Nothing to replay.")
else for (cmd <- replayCommands) {
@@ -482,21 +463,28 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
echo("")
}
}
- def resetCommand() {
- echo("Resetting interpreter state.")
- if (replayCommandStack.nonEmpty) {
- echo("Forgetting this session history:\n")
- replayCommands foreach echo
- echo("")
- replayCommandStack = Nil
+ /** `reset` the interpreter in an attempt to start fresh.
+ * Supplying settings creates a new compiler.
+ */
+ def resetCommand(line: String): Unit = {
+ def run(destructive: Boolean): Unit = {
+ echo("Resetting interpreter state.")
+ if (replayCommandStack.nonEmpty) {
+ echo("Forgetting this session history:\n")
+ replayCommands foreach echo
+ echo("")
+ replayCommandStack = Nil
+ }
+ if (intp.namedDefinedTerms.nonEmpty)
+ echo("Forgetting all expression results and named terms: " + intp.namedDefinedTerms.mkString(", "))
+ if (intp.definedTypes.nonEmpty)
+ echo("Forgetting defined types: " + intp.definedTypes.mkString(", "))
+ if (destructive) createInterpreter() else reset()
}
- if (intp.namedDefinedTerms.nonEmpty)
- echo("Forgetting all expression results and named terms: " + intp.namedDefinedTerms.mkString(", "))
- if (intp.definedTypes.nonEmpty)
- echo("Forgetting defined types: " + intp.definedTypes.mkString(", "))
-
- reset()
+ if (line.isEmpty) run(destructive = false)
+ else if (updateSettings(line)) run(destructive = true)
}
+ /** Resets without announcements. */
def reset() {
intp.reset()
unleashAndSetPhase()
@@ -619,6 +607,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
else File(filename).printlnAll(replayCommands: _*)
)
+ @deprecated("Use reset, replay or require to update class path", since = "2.11")
def addClasspath(arg: String): Unit = {
val f = File(arg).normalize
if (f.exists) {
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 6e30b73e0e..20b5a79aaa 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -295,22 +295,38 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
def originalPath(name: Name): String = typerOp path name
def originalPath(sym: Symbol): String = typerOp path sym
def flatPath(sym: Symbol): String = flatOp shift sym.javaClassName
+
def translatePath(path: String) = {
val sym = if (path endsWith "$") symbolOfTerm(path.init) else symbolOfIdent(path)
sym.toOption map flatPath
}
+
+ /** If path represents a class resource in the default package,
+ * see if the corresponding symbol has a class file that is a REPL artifact
+ * residing at a different resource path. Translate X.class to $line3/$read$$iw$$iw$X.class.
+ */
+ def translateSimpleResource(path: String): Option[String] = {
+ if (!(path contains '/') && (path endsWith ".class")) {
+ val name = path stripSuffix ".class"
+ val sym = if (name endsWith "$") symbolOfTerm(name.init) else symbolOfIdent(name)
+ def pathOf(s: String) = s"${s.replace('.', '/')}.class"
+ sym.toOption map (s => pathOf(flatPath(s)))
+ } else {
+ None
+ }
+ }
def translateEnclosingClass(n: String) = symbolOfTerm(n).enclClass.toOption map flatPath
+ /** If unable to find a resource foo.class, try taking foo as a symbol in scope
+ * and use its java class name as a resource to load.
+ *
+ * $intp.classLoader classBytes "Bippy" or $intp.classLoader getResource "Bippy.class" just work.
+ */
private class TranslatingClassLoader(parent: ClassLoader) extends util.AbstractFileClassLoader(replOutput.dir, parent) {
- /** Overridden here to try translating a simple name to the generated
- * class name if the original attempt fails. This method is used by
- * getResourceAsStream as well as findClass.
- */
- override protected def findAbstractFile(name: String): AbstractFile =
- super.findAbstractFile(name) match {
- case null if _initializeComplete => translatePath(name) map (super.findAbstractFile(_)) orNull
- case file => file
- }
+ override protected def findAbstractFile(name: String): AbstractFile = super.findAbstractFile(name) match {
+ case null if _initializeComplete => translateSimpleResource(name) map super.findAbstractFile orNull
+ case file => file
+ }
}
private def makeClassLoader(): util.AbstractFileClassLoader =
new TranslatingClassLoader(parentClassLoader match {
diff --git a/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
index a37cdc2ec8..bcba7b6dfd 100644
--- a/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
+++ b/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
@@ -102,6 +102,18 @@ trait MemberHandlers {
class GenericHandler(member: Tree) extends MemberHandler(member)
+ import scala.io.AnsiColor.{ BOLD, BLUE, GREEN, RESET }
+
+ def color(c: String, s: String) =
+ if (replProps.colorOk) string2code(BOLD) + string2code(c) + s + string2code(RESET)
+ else s
+
+ def colorName(s: String) =
+ color(BLUE, string2code(s))
+
+ def colorType(s: String) =
+ color(GREEN, string2code(s))
+
class ValHandler(member: ValDef) extends MemberDefHandler(member) {
val maxStringElements = 1000 // no need to mkString billions of elements
override def definesValue = true
@@ -119,15 +131,20 @@ trait MemberHandlers {
if (replProps.vids) s"""" + f"@$${System.identityHashCode($path)}%8x" + """"
else ""
- """ + "%s%s: %s = " + %s""".format(string2code(prettyName), vidString, string2code(req typeOf name), resultString)
+ val nameString = colorName(prettyName) + vidString
+ val typeString = colorType(req typeOf name)
+ s""" + "$nameString: $typeString = " + $resultString"""
}
}
}
class DefHandler(member: DefDef) extends MemberDefHandler(member) {
override def definesValue = flattensToEmpty(member.vparamss) // true if 0-arity
- override def resultExtractionCode(req: Request) =
- if (mods.isPublic) codegenln(name, ": ", req.typeOf(name)) else ""
+ override def resultExtractionCode(req: Request) = {
+ val nameString = colorName(name)
+ val typeString = colorType(req typeOf name)
+ if (mods.isPublic) s""" + "$nameString: $typeString\\n"""" else ""
+ }
}
abstract class MacroHandler(member: DefDef) extends MemberDefHandler(member) {
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
index 36e6dbbccc..8c4faf7278 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala
@@ -13,6 +13,9 @@ class ReplProps {
private def bool(name: String) = BooleanProp.keyExists(name)
private def int(name: String) = IntProp(name)
+ // This property is used in TypeDebugging. Let's recycle it.
+ val colorOk = bool("scala.color")
+
val info = bool("scala.repl.info")
val debug = bool("scala.repl.debug")
val trace = bool("scala.repl.trace")
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplReporter.scala b/src/repl/scala/tools/nsc/interpreter/ReplReporter.scala
index 88372334d6..e6f5a4089e 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplReporter.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplReporter.scala
@@ -32,6 +32,24 @@ class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.i
override def warning(pos: Position, msg: String): Unit = withoutTruncating(super.warning(pos, msg))
override def error(pos: Position, msg: String): Unit = withoutTruncating(super.error(pos, msg))
+ import scala.io.AnsiColor.{ RED, YELLOW, RESET }
+
+ def severityColor(severity: Severity): String = severity match {
+ case ERROR => RED
+ case WARNING => YELLOW
+ case INFO => RESET
+ }
+
+ override def print(pos: Position, msg: String, severity: Severity) {
+ val prefix = (
+ if (replProps.colorOk)
+ severityColor(severity) + clabel(severity) + RESET
+ else
+ clabel(severity)
+ )
+ printMessage(pos, prefix + msg)
+ }
+
override def printMessage(msg: String) {
// Avoiding deadlock if the compiler starts logging before
// the lazy val is complete.
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala b/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
index 43da5c6f12..1664546cab 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
@@ -28,5 +28,8 @@ trait ReplStrings {
def any2stringOf(x: Any, maxlen: Int) =
"scala.runtime.ScalaRunTime.replStringOf(%s, %s)".format(x, maxlen)
- def words(s: String) = (s.trim split "\\s+" filterNot (_ == "")).toList
+ // no escaped or nested quotes
+ private[this] val inquotes = """(['"])(.*?)\1""".r
+ def unquoted(s: String) = s match { case inquotes(_, w) => w ; case _ => s }
+ def words(s: String) = (s.trim split "\\s+" filterNot (_ == "") map unquoted).toList
}
diff --git a/src/scaladoc/scala/tools/nsc/ScalaDoc.scala b/src/scaladoc/scala/tools/nsc/ScalaDoc.scala
index 52a0c20a11..32a6ba0ce3 100644
--- a/src/scaladoc/scala/tools/nsc/ScalaDoc.scala
+++ b/src/scaladoc/scala/tools/nsc/ScalaDoc.scala
@@ -18,14 +18,10 @@ class ScalaDoc {
val versionMsg = "Scaladoc %s -- %s".format(Properties.versionString, Properties.copyrightString)
def process(args: Array[String]): Boolean = {
- var reporter: ConsoleReporter = null
+ var reporter: ScalaDocReporter = null
val docSettings = new doc.Settings(msg => reporter.error(FakePos("scaladoc"), msg + "\n scaladoc -help gives more information"),
msg => reporter.printMessage(msg))
- reporter = new ConsoleReporter(docSettings) {
- // need to do this so that the Global instance doesn't trash all the
- // symbols just because there was an error
- override def hasErrors = false
- }
+ reporter = new ScalaDocReporter(docSettings)
val command = new ScalaDoc.Command(args.toList, docSettings)
def hasFiles = command.files.nonEmpty || docSettings.uncompilableFiles.nonEmpty
@@ -50,12 +46,18 @@ class ScalaDoc {
}
finally reporter.printSummary()
- // not much point in returning !reporter.hasErrors when it has
- // been overridden with constant false.
- true
+ !reporter.reallyHasErrors
}
}
+class ScalaDocReporter(settings: Settings) extends ConsoleReporter(settings) {
+
+ // need to do sometimes lie so that the Global instance doesn't
+ // trash all the symbols just because there was an error
+ override def hasErrors = false
+ def reallyHasErrors = super.hasErrors
+}
+
object ScalaDoc extends ScalaDoc {
class Command(arguments: List[String], settings: doc.Settings) extends CompilerCommand(arguments, settings) {
override def cmdName = "scaladoc"
diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check
index 2dad608451..bbf5e9b528 100644
--- a/test/files/neg/patmatexhaust.check
+++ b/test/files/neg/patmatexhaust.check
@@ -12,7 +12,7 @@ It would fail on the following inputs: (Kult(_), Kult(_)), (Qult(), Qult())
^
patmatexhaust.scala:49: warning: match may not be exhaustive.
It would fail on the following inputs: Gp(), Gu
- def ma4(x:Deep) = x match { // missing cases: Gu, Gp
+ def ma4(x:Deep) = x match { // missing cases: Gu, Gp which is not abstract so must be included
^
patmatexhaust.scala:55: warning: unreachable code
case _ if 1 == 0 =>
diff --git a/test/files/neg/patmatexhaust.flags b/test/files/neg/patmatexhaust.flags
index 85d8eb2ba2..3b01ca062c 100644
--- a/test/files/neg/patmatexhaust.flags
+++ b/test/files/neg/patmatexhaust.flags
@@ -1 +1 @@
--Xfatal-warnings
+-Xfatal-warnings -Ypatmat-exhaust-depth off \ No newline at end of file
diff --git a/test/files/neg/patmatexhaust.scala b/test/files/neg/patmatexhaust.scala
index f937197829..26f0c12a91 100644
--- a/test/files/neg/patmatexhaust.scala
+++ b/test/files/neg/patmatexhaust.scala
@@ -46,7 +46,7 @@ class TestSealedExhaustive { // compile only
case _ =>
}
- def ma4(x:Deep) = x match { // missing cases: Gu, Gp
+ def ma4(x:Deep) = x match { // missing cases: Gu, Gp which is not abstract so must be included
case Ga =>
}
diff --git a/test/files/neg/t3240.check b/test/files/neg/t3240.check
deleted file mode 100644
index efae682c66..0000000000
--- a/test/files/neg/t3240.check
+++ /dev/null
@@ -1,4 +0,0 @@
-t3240.scala:3: error: only classes can have declared but undefined members
- type t
- ^
-one error found
diff --git a/test/files/neg/t6902.scala b/test/files/neg/t6902.scala
index ce5ff8b6fb..627c324279 100644
--- a/test/files/neg/t6902.scala
+++ b/test/files/neg/t6902.scala
@@ -16,7 +16,7 @@ object Test {
// at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:50)
// at scala.tools.nsc.Global.abort(Global.scala:249)
// at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$jcode$.emitSWITCH(GenASM.scala:1850)
- ((1: Byte): @unchecked @annotation.switch) match {
+ ((1: Byte): @unchecked) match {
case 1 => 2
case 1 => 3 // crash
}
diff --git a/test/files/neg/t8217-local-alias-requires-rhs.check b/test/files/neg/t8217-local-alias-requires-rhs.check
new file mode 100644
index 0000000000..0d4f0864ba
--- /dev/null
+++ b/test/files/neg/t8217-local-alias-requires-rhs.check
@@ -0,0 +1,10 @@
+t8217-local-alias-requires-rhs.scala:6: error: only classes can have declared but undefined members
+ type B
+ ^
+t8217-local-alias-requires-rhs.scala:3: error: only classes can have declared but undefined members
+ type A
+ ^
+t8217-local-alias-requires-rhs.scala:14: error: only classes can have declared but undefined members
+ def this(a: Any) = { this(); type C }
+ ^
+three errors found
diff --git a/test/files/neg/t8217-local-alias-requires-rhs.scala b/test/files/neg/t8217-local-alias-requires-rhs.scala
new file mode 100644
index 0000000000..12b7976835
--- /dev/null
+++ b/test/files/neg/t8217-local-alias-requires-rhs.scala
@@ -0,0 +1,15 @@
+trait Alias {
+ def foo = {
+ type A
+ }
+ val bar = {
+ type B
+ object O {
+ type OK
+ }
+ }
+}
+
+class C {
+ def this(a: Any) = { this(); type C }
+}
diff --git a/test/files/neg/t8291.check b/test/files/neg/t8291.check
new file mode 100644
index 0000000000..c9972e5575
--- /dev/null
+++ b/test/files/neg/t8291.check
@@ -0,0 +1,7 @@
+t8291.scala:5: error: Could not find implicit for Int or String
+ implicitly[X[Int, String]]
+ ^
+t8291.scala:6: error: Could not find implicit for Int or String
+ implicitly[Z[String]]
+ ^
+two errors found
diff --git a/test/files/neg/t8291.scala b/test/files/neg/t8291.scala
new file mode 100644
index 0000000000..b344586a56
--- /dev/null
+++ b/test/files/neg/t8291.scala
@@ -0,0 +1,7 @@
+@scala.annotation.implicitNotFound("Could not find implicit for ${T} or ${U}") trait X[T, U]
+
+object Test {
+ type Z[U] = X[Int, U]
+ implicitly[X[Int, String]]
+ implicitly[Z[String]]
+}
diff --git a/test/files/neg/t8430.check b/test/files/neg/t8430.check
index 7c6a73ce53..dbc0c70bba 100644
--- a/test/files/neg/t8430.check
+++ b/test/files/neg/t8430.check
@@ -1,25 +1,25 @@
t8430.scala:15: warning: match may not be exhaustive.
-It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP
+It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP
(tree: Tree) => tree match {case LetL(CharLit) => ??? }
^
t8430.scala:16: warning: match may not be exhaustive.
-It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP
+It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP
(tree: Tree) => tree match {case LetL(CharLit) => ??? }
^
t8430.scala:17: warning: match may not be exhaustive.
-It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP
+It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP
(tree: Tree) => tree match {case LetL(CharLit) => ??? }
^
t8430.scala:18: warning: match may not be exhaustive.
-It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP
+It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP
(tree: Tree) => tree match {case LetL(CharLit) => ??? }
^
t8430.scala:19: warning: match may not be exhaustive.
-It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP
+It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP
(tree: Tree) => tree match {case LetL(CharLit) => ??? }
^
t8430.scala:20: warning: match may not be exhaustive.
-It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP
+It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP
(tree: Tree) => tree match {case LetL(CharLit) => ??? }
^
error: No warnings can be incurred under -Xfatal-warnings.
diff --git a/test/files/neg/t8430.flags b/test/files/neg/t8430.flags
index 85d8eb2ba2..6f60189a8d 100644
--- a/test/files/neg/t8430.flags
+++ b/test/files/neg/t8430.flags
@@ -1 +1 @@
--Xfatal-warnings
+-Xfatal-warnings -Ypatmat-exhaust-depth off
diff --git a/test/files/neg/t845.check b/test/files/neg/t845.check
deleted file mode 100644
index 07ed7e417b..0000000000
--- a/test/files/neg/t845.check
+++ /dev/null
@@ -1,4 +0,0 @@
-t845.scala:4: error: only classes can have declared but undefined members
- type Bar;
- ^
-one error found
diff --git a/test/files/neg/t8731.check b/test/files/neg/t8731.check
new file mode 100644
index 0000000000..2a9af475fc
--- /dev/null
+++ b/test/files/neg/t8731.check
@@ -0,0 +1,9 @@
+t8731.scala:5: warning: matches with two cases or fewer are emitted using if-then-else instead of switch
+ def f(x: Int) = (x: @annotation.switch) match {
+ ^
+t8731.scala:10: warning: could not emit switch for @switch annotated match
+ def g(x: Int) = (x: @annotation.switch) match {
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t8731.flags b/test/files/neg/t8731.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/neg/t8731.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t8731.scala b/test/files/neg/t8731.scala
new file mode 100644
index 0000000000..d93fe706ad
--- /dev/null
+++ b/test/files/neg/t8731.scala
@@ -0,0 +1,15 @@
+class C {
+ // not a compile-time constant due to return type
+ final val K: Int = 20
+
+ def f(x: Int) = (x: @annotation.switch) match {
+ case K => 0
+ case 2 => 1
+ }
+
+ def g(x: Int) = (x: @annotation.switch) match {
+ case K => 0
+ case 2 => 1
+ case 3 => 2
+ }
+}
diff --git a/test/files/neg/t8869.check b/test/files/neg/t8869.check
new file mode 100644
index 0000000000..40b8570f9f
--- /dev/null
+++ b/test/files/neg/t8869.check
@@ -0,0 +1,7 @@
+t8869.scala:5: error: class Option takes type parameters
+ def value: TC[({type l1[x] = Option})#l1] = ??? // error not reported!
+ ^
+t8869.scala:7: error: class Option takes type parameters
+ type l2[x] = Option // error correctly reported
+ ^
+two errors found
diff --git a/test/files/neg/t8869.scala b/test/files/neg/t8869.scala
new file mode 100644
index 0000000000..0c7f0c9451
--- /dev/null
+++ b/test/files/neg/t8869.scala
@@ -0,0 +1,10 @@
+class TC[T[_]] {
+ def identity[A](a: T[A]): T[A] = a
+}
+object Test {
+ def value: TC[({type l1[x] = Option})#l1] = ??? // error not reported!
+
+ type l2[x] = Option // error correctly reported
+ def value1: TC[l2] = ???
+}
+
diff --git a/test/files/neg/t8890.check b/test/files/neg/t8890.check
new file mode 100644
index 0000000000..1b69d6cf30
--- /dev/null
+++ b/test/files/neg/t8890.check
@@ -0,0 +1,4 @@
+t8890.scala:6: error: not found: type Str
+ def bar(x: Str): Unit = ???
+ ^
+one error found
diff --git a/test/files/neg/t8890.scala b/test/files/neg/t8890.scala
new file mode 100644
index 0000000000..cbdeb11d43
--- /dev/null
+++ b/test/files/neg/t8890.scala
@@ -0,0 +1,11 @@
+package foo
+
+class A {
+ /** The other */
+ def bar(x: Int): Unit = ???
+ def bar(x: Str): Unit = ???
+}
+
+class B {
+ (new A).bar(0)
+} \ No newline at end of file
diff --git a/test/files/pos/switch-small.flags b/test/files/pos/switch-small.flags
deleted file mode 100644
index 85d8eb2ba2..0000000000
--- a/test/files/pos/switch-small.flags
+++ /dev/null
@@ -1 +0,0 @@
--Xfatal-warnings
diff --git a/test/files/pos/switch-small.scala b/test/files/pos/switch-small.scala
deleted file mode 100644
index 9de9ca028e..0000000000
--- a/test/files/pos/switch-small.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-import annotation._
-
-object Test {
- def f(x: Int) = (x: @switch) match {
- case 1 => 1
- case _ => 2
- }
-}
diff --git a/test/files/neg/t3240.scala b/test/files/pos/t3240.scala
index cf197a406d..cf197a406d 100644
--- a/test/files/neg/t3240.scala
+++ b/test/files/pos/t3240.scala
diff --git a/test/files/pos/t8267.scala b/test/files/pos/t8267.scala
new file mode 100644
index 0000000000..37b498fe3e
--- /dev/null
+++ b/test/files/pos/t8267.scala
@@ -0,0 +1,33 @@
+class Bippy { trait Foo[A] }
+
+final class RichBippy[C <: Bippy with Singleton](val c1: C) {
+ def f: Int = 1
+ def f[A](x: A)(ev: c1.Foo[A]): Int = 2
+
+ def g[A <: Nothing](x: A): Int = 1
+ def g[A](x: A)(ev: c1.Foo[A]): Int = 2
+
+ def h[A](x: A)(ev: c1.Foo[A]): Int = 1
+
+ def i(x: Nothing): Int = 1
+ def i(x: AnyRef)(ev: c1.Foo[x.type]): Int = 2
+}
+
+object p {
+
+ val c = new Bippy
+ val d0 = new RichBippy[c.type](c)
+ def d1 = new RichBippy[c.type](c)
+
+ d0.f[Int](5)(null: c.Foo[Int]) // ok
+ d1.f[Int](5)(null: c.Foo[Int]) // fails
+
+ d0.g[Int](5)(null: c.Foo[Int]) // ok
+ d1.g[Int](5)(null: c.Foo[Int]) // fails
+
+ d0.h[Int](5)(null: c.Foo[Int]) // ok
+ d1.h[Int](5)(null: c.Foo[Int]) // ok
+
+ d0.i("")(null) // ok
+ d1.i("")(null) // ok
+}
diff --git a/test/files/neg/t845.scala b/test/files/pos/t845.scala
index ddf6a16f32..ddf6a16f32 100644
--- a/test/files/neg/t845.scala
+++ b/test/files/pos/t845.scala
diff --git a/test/files/pos/t8868a/Sub_2.scala b/test/files/pos/t8868a/Sub_2.scala
new file mode 100644
index 0000000000..a19b529c88
--- /dev/null
+++ b/test/files/pos/t8868a/Sub_2.scala
@@ -0,0 +1 @@
+class Sub extends T
diff --git a/test/files/pos/t8868a/T_1.scala b/test/files/pos/t8868a/T_1.scala
new file mode 100644
index 0000000000..9fb97b1413
--- /dev/null
+++ b/test/files/pos/t8868a/T_1.scala
@@ -0,0 +1,6 @@
+class C
+
+trait T {
+ @deprecated(since = "", message = "")
+ class X
+}
diff --git a/test/files/pos/t8868b/Sub_2.scala b/test/files/pos/t8868b/Sub_2.scala
new file mode 100644
index 0000000000..58b44db2b3
--- /dev/null
+++ b/test/files/pos/t8868b/Sub_2.scala
@@ -0,0 +1,2 @@
+class Sub extends T
+
diff --git a/test/files/pos/t8868b/T_1.scala b/test/files/pos/t8868b/T_1.scala
new file mode 100644
index 0000000000..0b71cfdaa3
--- /dev/null
+++ b/test/files/pos/t8868b/T_1.scala
@@ -0,0 +1,4 @@
+@deprecated(since = "2.4.0", message = "")
+trait T {
+ class X
+}
diff --git a/test/files/pos/t8868c/Sub_2.scala b/test/files/pos/t8868c/Sub_2.scala
new file mode 100644
index 0000000000..58b44db2b3
--- /dev/null
+++ b/test/files/pos/t8868c/Sub_2.scala
@@ -0,0 +1,2 @@
+class Sub extends T
+
diff --git a/test/files/pos/t8868c/T_1.scala b/test/files/pos/t8868c/T_1.scala
new file mode 100644
index 0000000000..dc541950d8
--- /dev/null
+++ b/test/files/pos/t8868c/T_1.scala
@@ -0,0 +1,9 @@
+class C(a: Any) extends annotation.StaticAnnotation
+
+@C({val x = 0; x})
+trait T {
+ class X
+
+ @C({val x = 0; x})
+ def foo = 42
+}
diff --git a/test/files/pos/t8894.scala b/test/files/pos/t8894.scala
new file mode 100644
index 0000000000..3b26f1ae7e
--- /dev/null
+++ b/test/files/pos/t8894.scala
@@ -0,0 +1,12 @@
+class CC(val i: Int, val s: String)
+object CC extends {
+ type P = (Int, String)
+
+ //def unapply(c: CC): Option[(Int, String)] = Some((c.i, c.s)) // OK
+ def unapply(c: CC): Option[P] = Some((c.i, c.s)) // fails (because of the type alias)
+}
+
+class Test {
+ val cc = new CC(23, "foo")
+ val CC(i, s) = cc
+} \ No newline at end of file
diff --git a/test/disabled/presentation/doc.check b/test/files/presentation/doc.check
index 5a3ff13151..5a3ff13151 100644
--- a/test/disabled/presentation/doc.check
+++ b/test/files/presentation/doc.check
diff --git a/test/disabled/presentation/doc/doc.scala b/test/files/presentation/doc/doc.scala
index f2233f1828..f2233f1828 100755
--- a/test/disabled/presentation/doc/doc.scala
+++ b/test/files/presentation/doc/doc.scala
diff --git a/test/disabled/presentation/doc/src/Class.scala b/test/files/presentation/doc/src/Class.scala
index a974bd6f5c..a974bd6f5c 100755
--- a/test/disabled/presentation/doc/src/Class.scala
+++ b/test/files/presentation/doc/src/Class.scala
diff --git a/test/disabled/presentation/doc/src/p/Base.scala b/test/files/presentation/doc/src/p/Base.scala
index d91632b6f6..d91632b6f6 100755
--- a/test/disabled/presentation/doc/src/p/Base.scala
+++ b/test/files/presentation/doc/src/p/Base.scala
diff --git a/test/disabled/presentation/doc/src/p/Derived.scala b/test/files/presentation/doc/src/p/Derived.scala
index 1a9c9a26d1..1a9c9a26d1 100755
--- a/test/disabled/presentation/doc/src/p/Derived.scala
+++ b/test/files/presentation/doc/src/p/Derived.scala
diff --git a/test/files/run/t4594-repl-settings.scala b/test/files/run/t4594-repl-settings.scala
index 4202991607..db5dc19866 100644
--- a/test/files/run/t4594-repl-settings.scala
+++ b/test/files/run/t4594-repl-settings.scala
@@ -14,7 +14,7 @@ object Test extends SessionTest {
|warning: there was one deprecation warning; re-run with -deprecation for details
|a: String
|
- |scala> :settings +deprecation
+ |scala> :settings -deprecation
|
|scala> def b = depp
|<console>:8: warning: method depp is deprecated: Please don't do that.
diff --git a/test/files/run/t4788-separate-compilation.check b/test/files/run/t4788-separate-compilation.check
new file mode 100644
index 0000000000..172ad90102
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation.check
@@ -0,0 +1,5 @@
+Some(@Ljava/lang/Deprecated;())
+None
+None
+Some(@LCAnnotation;() // invisible)
+Some(@LRAnnotation;())
diff --git a/test/files/run/t4788-separate-compilation/CAnnotation_1.java b/test/files/run/t4788-separate-compilation/CAnnotation_1.java
new file mode 100644
index 0000000000..7120218d62
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/CAnnotation_1.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.CLASS;
+
+@Retention(value=CLASS)
+@interface CAnnotation {}
diff --git a/test/files/run/t4788-separate-compilation/C_1.scala b/test/files/run/t4788-separate-compilation/C_1.scala
new file mode 100644
index 0000000000..aba9b595e4
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/C_1.scala
@@ -0,0 +1,2 @@
+@CAnnotation
+class C
diff --git a/test/files/run/t4788-separate-compilation/D_1.scala b/test/files/run/t4788-separate-compilation/D_1.scala
new file mode 100644
index 0000000000..c2479fba86
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/D_1.scala
@@ -0,0 +1,5 @@
+@Deprecated
+class DJava
+
+@deprecated("", "")
+class DScala
diff --git a/test/files/run/t4788-separate-compilation/RAnnotation_1.java b/test/files/run/t4788-separate-compilation/RAnnotation_1.java
new file mode 100644
index 0000000000..f24cf66f7b
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/RAnnotation_1.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(value=RUNTIME)
+@interface RAnnotation {}
diff --git a/test/files/run/t4788-separate-compilation/R_1.scala b/test/files/run/t4788-separate-compilation/R_1.scala
new file mode 100644
index 0000000000..ab0cd065d9
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/R_1.scala
@@ -0,0 +1,2 @@
+@RAnnotation
+class R
diff --git a/test/files/run/t4788-separate-compilation/SAnnotation_1.java b/test/files/run/t4788-separate-compilation/SAnnotation_1.java
new file mode 100644
index 0000000000..471f27d82a
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/SAnnotation_1.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+@Retention(value=SOURCE)
+@interface SAnnotation {}
diff --git a/test/files/run/t4788-separate-compilation/S_1.scala b/test/files/run/t4788-separate-compilation/S_1.scala
new file mode 100644
index 0000000000..f8756d9bc8
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/S_1.scala
@@ -0,0 +1,2 @@
+@SAnnotation
+class S
diff --git a/test/files/run/t4788-separate-compilation/Test_2.scala b/test/files/run/t4788-separate-compilation/Test_2.scala
new file mode 100644
index 0000000000..cbbb5ff386
--- /dev/null
+++ b/test/files/run/t4788-separate-compilation/Test_2.scala
@@ -0,0 +1,35 @@
+import java.io.PrintWriter;
+
+import scala.tools.partest.BytecodeTest
+import scala.tools.asm.util._
+import scala.tools.nsc.util.stringFromWriter
+
+object Test extends BytecodeTest {
+ def annotationsForClass(className: String): Option[String] = {
+ val classNode = loadClassNode(className, skipDebugInfo = false)
+ val textifier = new Textifier
+ classNode.accept(new TraceClassVisitor(null, textifier, null))
+
+ val classString = stringFromWriter(w => textifier.print(w))
+ classString
+ .split('\n')
+ .filterNot(_.contains("@Lscala/reflect/ScalaSignature"))
+ .find(_.contains("@L"))
+ .map(_.trim)
+ }
+
+ def show {
+ // It seems like @java.lang.Deprecated shows up in both the
+ // Deprecated attribute and RuntimeVisibleAnnotation attribute,
+ // while @scala.deprecated only shows up in the Deprecated attribute.
+ // The check file just documents status quo, not sure if Scala
+ // should brought in line with Java or not...
+ // See the commit message and SI-8883 for more info.
+ println(annotationsForClass("DJava"))
+ println(annotationsForClass("DScala"))
+
+ println(annotationsForClass("S"))
+ println(annotationsForClass("C"))
+ println(annotationsForClass("R"))
+ }
+}
diff --git a/test/files/run/t4788.check b/test/files/run/t4788.check
new file mode 100644
index 0000000000..172ad90102
--- /dev/null
+++ b/test/files/run/t4788.check
@@ -0,0 +1,5 @@
+Some(@Ljava/lang/Deprecated;())
+None
+None
+Some(@LCAnnotation;() // invisible)
+Some(@LRAnnotation;())
diff --git a/test/files/run/t4788/C.scala b/test/files/run/t4788/C.scala
new file mode 100644
index 0000000000..aba9b595e4
--- /dev/null
+++ b/test/files/run/t4788/C.scala
@@ -0,0 +1,2 @@
+@CAnnotation
+class C
diff --git a/test/files/run/t4788/CAnnotation.java b/test/files/run/t4788/CAnnotation.java
new file mode 100644
index 0000000000..7120218d62
--- /dev/null
+++ b/test/files/run/t4788/CAnnotation.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.CLASS;
+
+@Retention(value=CLASS)
+@interface CAnnotation {}
diff --git a/test/files/run/t4788/D.scala b/test/files/run/t4788/D.scala
new file mode 100644
index 0000000000..c2479fba86
--- /dev/null
+++ b/test/files/run/t4788/D.scala
@@ -0,0 +1,5 @@
+@Deprecated
+class DJava
+
+@deprecated("", "")
+class DScala
diff --git a/test/files/run/t4788/R.scala b/test/files/run/t4788/R.scala
new file mode 100644
index 0000000000..ab0cd065d9
--- /dev/null
+++ b/test/files/run/t4788/R.scala
@@ -0,0 +1,2 @@
+@RAnnotation
+class R
diff --git a/test/files/run/t4788/RAnnotation.java b/test/files/run/t4788/RAnnotation.java
new file mode 100644
index 0000000000..f24cf66f7b
--- /dev/null
+++ b/test/files/run/t4788/RAnnotation.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(value=RUNTIME)
+@interface RAnnotation {}
diff --git a/test/files/run/t4788/S.scala b/test/files/run/t4788/S.scala
new file mode 100644
index 0000000000..f8756d9bc8
--- /dev/null
+++ b/test/files/run/t4788/S.scala
@@ -0,0 +1,2 @@
+@SAnnotation
+class S
diff --git a/test/files/run/t4788/SAnnotation.java b/test/files/run/t4788/SAnnotation.java
new file mode 100644
index 0000000000..471f27d82a
--- /dev/null
+++ b/test/files/run/t4788/SAnnotation.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+@Retention(value=SOURCE)
+@interface SAnnotation {}
diff --git a/test/files/run/t4788/Test.scala b/test/files/run/t4788/Test.scala
new file mode 100644
index 0000000000..cbbb5ff386
--- /dev/null
+++ b/test/files/run/t4788/Test.scala
@@ -0,0 +1,35 @@
+import java.io.PrintWriter;
+
+import scala.tools.partest.BytecodeTest
+import scala.tools.asm.util._
+import scala.tools.nsc.util.stringFromWriter
+
+object Test extends BytecodeTest {
+ def annotationsForClass(className: String): Option[String] = {
+ val classNode = loadClassNode(className, skipDebugInfo = false)
+ val textifier = new Textifier
+ classNode.accept(new TraceClassVisitor(null, textifier, null))
+
+ val classString = stringFromWriter(w => textifier.print(w))
+ classString
+ .split('\n')
+ .filterNot(_.contains("@Lscala/reflect/ScalaSignature"))
+ .find(_.contains("@L"))
+ .map(_.trim)
+ }
+
+ def show {
+ // It seems like @java.lang.Deprecated shows up in both the
+ // Deprecated attribute and RuntimeVisibleAnnotation attribute,
+ // while @scala.deprecated only shows up in the Deprecated attribute.
+ // The check file just documents status quo, not sure if Scala
+ // should brought in line with Java or not...
+ // See the commit message and SI-8883 for more info.
+ println(annotationsForClass("DJava"))
+ println(annotationsForClass("DScala"))
+
+ println(annotationsForClass("S"))
+ println(annotationsForClass("C"))
+ println(annotationsForClass("R"))
+ }
+}
diff --git a/test/files/run/t5830.check b/test/files/run/t5830.check
index 675387eb8e..9260854676 100644
--- a/test/files/run/t5830.check
+++ b/test/files/run/t5830.check
@@ -1,5 +1,6 @@
a with oef
a with oef
+a with oef
a
def with oef
def
diff --git a/test/files/run/t5830.scala b/test/files/run/t5830.scala
index 5d808bfa28..03b9c540e0 100644
--- a/test/files/run/t5830.scala
+++ b/test/files/run/t5830.scala
@@ -1,12 +1,11 @@
import scala.annotation.switch
object Test extends App {
- // TODO: should not emit a switch
- // def noSwitch(ch: Char, eof: Boolean) = (ch: @switch) match {
- // case 'a' if eof => println("a with oef") // then branch
- // }
+ def noSwitch(ch: Char, eof: Boolean) = ch match {
+ case 'a' if eof => println("a with oef") // then branch
+ }
- def onlyThen(ch: Char, eof: Boolean) = (ch: @switch) match {
+ def onlyThen(ch: Char, eof: Boolean) = ch match {
case 'a' if eof => println("a with oef") // then branch
case 'c' =>
}
@@ -18,7 +17,7 @@ object Test extends App {
case 'c' =>
}
- def defaultUnguarded(ch: Char, eof: Boolean) = (ch: @switch) match {
+ def defaultUnguarded(ch: Char, eof: Boolean) = ch match {
case ' ' if eof => println("spacey oef")
case _ => println("default")
}
@@ -44,7 +43,7 @@ object Test extends App {
// case 'c' =>
// }
- // noSwitch('a', true)
+ noSwitch('a', true)
onlyThen('a', true) // 'a with oef'
ifThenElse('a', true) // 'a with oef'
ifThenElse('a', false) // 'a'
diff --git a/test/files/run/t6011c.scala b/test/files/run/t6011c.scala
index 0647e3f81a..96a685b9cf 100644
--- a/test/files/run/t6011c.scala
+++ b/test/files/run/t6011c.scala
@@ -6,7 +6,7 @@ object Test extends App {
// at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:50)
// at scala.tools.nsc.Global.abort(Global.scala:249)
// at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$jcode$.emitSWITCH(GenASM.scala:1850)
- ((1: Byte): @unchecked @annotation.switch) match {
+ ((1: Byte): @unchecked) match {
case 1 => 2
case 1 => 3 // crash
}
diff --git a/test/files/run/t6622.check b/test/files/run/t6622.check
new file mode 100644
index 0000000000..5d006d88e6
--- /dev/null
+++ b/test/files/run/t6622.check
@@ -0,0 +1,10 @@
+ O1.resultVal isMemberClass = false, null
+class A$1
+ O1.resultDef isMemberClass = false, public void O1$.resultDef()
+class A$2
+ C2.resultVal isMemberClass = false, null
+class $B$1
+ O3.resultDef isMemberClass = false, public void O3$.resultDef()
+class C$1
+ O4.resultDefDefault isMemberClass = false, public java.lang.Object O4$.resultDefDefault$default$1()
+class C$2
diff --git a/test/files/run/t6622.scala b/test/files/run/t6622.scala
new file mode 100644
index 0000000000..de8ffa01bf
--- /dev/null
+++ b/test/files/run/t6622.scala
@@ -0,0 +1,50 @@
+import Test.check
+
+object O1 {
+ lazy val resultVal = {
+ class A
+ check("O1.resultVal", classOf[A])
+ }
+
+ def resultDef = {
+ class A
+ check("O1.resultDef", classOf[A])
+ }
+}
+
+class C2 {
+ val resultVal = {
+ val tmp = {
+ class B
+ check("C2.resultVal", classOf[B])
+ }
+ }
+}
+
+object O3 {
+ def resultDef = {
+ class C
+ check("O3.resultDef", classOf[C])
+ }
+}
+
+object O4 {
+ def resultDefDefault(a: Any = {
+ class C
+ check("O4.resultDefDefault", classOf[C])
+ }) = ();
+}
+
+
+object Test extends App {
+ def check(desc: String, clazz: Class[_]) {
+ println(s" $desc isMemberClass = ${clazz.isMemberClass}, ${clazz.getEnclosingMethod}")
+ println(reflect.runtime.currentMirror.classSymbol(clazz))
+ }
+
+ O1.resultVal
+ O1.resultDef
+ new C2().resultVal
+ O3.resultDef
+ O4.resultDefDefault()
+}
diff --git a/test/files/run/t8087.scala b/test/files/run/t8087.scala
new file mode 100644
index 0000000000..6047211756
--- /dev/null
+++ b/test/files/run/t8087.scala
@@ -0,0 +1,12 @@
+trait Foo {
+ @volatile private[this] var x: String = ""
+ @volatile private var y: String = ""
+}
+
+class Bar extends Foo
+
+object Test extends App {
+ classOf[Bar].getDeclaredFields.foreach(f => {
+ assert(java.lang.reflect.Modifier.isVolatile(f.getModifiers), f.getName)
+ })
+}
diff --git a/test/files/run/t8445.check b/test/files/run/t8445.check
new file mode 100644
index 0000000000..41fd6d3ed1
--- /dev/null
+++ b/test/files/run/t8445.check
@@ -0,0 +1 @@
+warning: there was one feature warning; re-run with -feature for details
diff --git a/test/files/run/t8445.scala b/test/files/run/t8445.scala
new file mode 100644
index 0000000000..ed196b62a2
--- /dev/null
+++ b/test/files/run/t8445.scala
@@ -0,0 +1,11 @@
+object X {
+ class Y
+ def y = new Y {
+ class Z
+ def z = classOf[Z]
+ }
+}
+
+object Test extends App {
+ assert(X.y.z.getEnclosingClass.getName == "X$$anon$1")
+}
diff --git a/test/files/run/t8843-repl-xlat.scala b/test/files/run/t8843-repl-xlat.scala
new file mode 100644
index 0000000000..6426dbe7d4
--- /dev/null
+++ b/test/files/run/t8843-repl-xlat.scala
@@ -0,0 +1,33 @@
+
+import scala.tools.partest.SessionTest
+
+// Handy hamburger helper for repl resources
+object Test extends SessionTest {
+ def session =
+"""Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala> $intp.isettings.unwrapStrings = false
+$intp.isettings.unwrapStrings: Boolean = false
+
+scala> class Bippy
+defined class Bippy
+
+scala> $intp.classLoader getResource "Bippy.class"
+res0: java.net.URL = memory:(memory)/$line4/$read$$iw$$iw$Bippy.class
+
+scala> ($intp.classLoader getResources "Bippy.class").nextElement
+res1: java.net.URL = memory:(memory)/$line4/$read$$iw$$iw$Bippy.class
+
+scala> ($intp.classLoader classBytes "Bippy").nonEmpty
+res2: Boolean = true
+
+scala> ($intp.classLoader classAsStream "Bippy") != null
+res3: Boolean = true
+
+scala> $intp.classLoader getResource "Bippy"
+res4: java.net.URL = null
+
+scala> :quit"""
+}
+
diff --git a/test/files/run/t8845.flags b/test/files/run/t8845.flags
new file mode 100644
index 0000000000..aada25f80d
--- /dev/null
+++ b/test/files/run/t8845.flags
@@ -0,0 +1 @@
+-Ybackend:GenBCode -Ynooptimize
diff --git a/test/files/run/t8845.scala b/test/files/run/t8845.scala
new file mode 100644
index 0000000000..8ccdbdadc7
--- /dev/null
+++ b/test/files/run/t8845.scala
@@ -0,0 +1,17 @@
+// crashes compiler under GenASM, works under GenBCode.
+object Interpreter {
+ def mkDataProp(i: Int) = i
+ def break(n: Int): Unit =
+ try {
+ n match {
+ case _ =>
+ val newDesc = mkDataProp(n)
+ n match { case _ => return }
+ }
+ } catch { case e: Throwable => }
+ finally { }
+}
+
+object Test extends App {
+ Interpreter.break(0)
+}
diff --git a/test/files/run/t8888.flags b/test/files/run/t8888.flags
new file mode 100644
index 0000000000..48b438ddf8
--- /dev/null
+++ b/test/files/run/t8888.flags
@@ -0,0 +1 @@
+-Ydelambdafy:method
diff --git a/test/files/run/t8888.scala b/test/files/run/t8888.scala
new file mode 100644
index 0000000000..36cc1ddf3e
--- /dev/null
+++ b/test/files/run/t8888.scala
@@ -0,0 +1,12 @@
+class C {
+ final def resume: Unit = (this: Any) match {
+ case x : C => (x: Any) match {
+ case y : C =>
+ () => (x, y) // used to trigger a ClassFormatError under -Ydelambdafy:method
+ }
+ }
+}
+
+object Test extends App {
+ new C().resume
+}
diff --git a/test/files/run/t8907.scala b/test/files/run/t8907.scala
new file mode 100644
index 0000000000..7952ac82d9
--- /dev/null
+++ b/test/files/run/t8907.scala
@@ -0,0 +1,39 @@
+import scala.tools.partest._
+import java.io.File
+
+object Test extends StoreReporterDirectTest {
+ def code = ???
+
+ def compileCode(code: String) = {
+ val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
+ compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
+ }
+
+ def show(): Unit = {
+ compileCode("""
+ class C { class Inner }
+
+ class D {
+ object O {
+ def foo(c: C)(i: c.Inner): c.Inner = ???
+ }
+ }
+ """)
+ assert(filteredInfos.isEmpty, filteredInfos)
+ deleteClass("C")
+ compileCode("""
+ class E {
+ def foo = {
+ (null: D).toString
+ }
+ }
+ """)
+ assert(storeReporter.infos.isEmpty, storeReporter.infos.mkString("\n")) // Included a MissingRequirementError before.
+ }
+
+ def deleteClass(name: String) {
+ val classFile = new File(testOutput.path, name + ".class")
+ assert(classFile.exists)
+ assert(classFile.delete())
+ }
+}
diff --git a/test/files/run/virtpatmat_nested_lists.flags b/test/files/run/virtpatmat_nested_lists.flags
new file mode 100644
index 0000000000..ca9a4c0697
--- /dev/null
+++ b/test/files/run/virtpatmat_nested_lists.flags
@@ -0,0 +1 @@
+-Ypatmat-exhaust-depth off \ No newline at end of file
diff --git a/test/files/run/virtpatmat_opt_sharing.flags b/test/files/run/virtpatmat_opt_sharing.flags
new file mode 100644
index 0000000000..ca9a4c0697
--- /dev/null
+++ b/test/files/run/virtpatmat_opt_sharing.flags
@@ -0,0 +1 @@
+-Ypatmat-exhaust-depth off \ No newline at end of file
diff --git a/test/junit/scala/collection/PagedSeq.scala b/test/junit/scala/collection/immutable/PagedSeqTest.scala
index 5f83cf6f31..5f83cf6f31 100644
--- a/test/junit/scala/collection/PagedSeq.scala
+++ b/test/junit/scala/collection/immutable/PagedSeqTest.scala
diff --git a/test/junit/scala/collection/QueueTest.scala b/test/junit/scala/collection/immutable/QueueTest.scala
index 9a40d8fc90..9a40d8fc90 100644
--- a/test/junit/scala/collection/QueueTest.scala
+++ b/test/junit/scala/collection/immutable/QueueTest.scala
diff --git a/test/junit/scala/collection/NumericRangeTest.scala b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
index 3980c31577..3980c31577 100644
--- a/test/junit/scala/collection/NumericRangeTest.scala
+++ b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
diff --git a/test/junit/scala/collection/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala
index 6dc1c79a48..6dc1c79a48 100644
--- a/test/junit/scala/collection/StreamTest.scala
+++ b/test/junit/scala/collection/immutable/StreamTest.scala
diff --git a/test/junit/scala/collection/ArraySortingTest.scala b/test/junit/scala/collection/mutable/ArraySortingTest.scala
index 4e54b39ce7..4e54b39ce7 100644
--- a/test/junit/scala/collection/ArraySortingTest.scala
+++ b/test/junit/scala/collection/mutable/ArraySortingTest.scala
diff --git a/test/junit/scala/collection/PriorityQueueTest.scala b/test/junit/scala/collection/mutable/PriorityQueueTest.scala
index a14f1bf4c8..a14f1bf4c8 100644
--- a/test/junit/scala/collection/PriorityQueueTest.scala
+++ b/test/junit/scala/collection/mutable/PriorityQueueTest.scala
diff --git a/test/junit/scala/collection/VectorTest.scala b/test/junit/scala/collection/mutable/VectorTest.scala
index e9c4d44a72..e9c4d44a72 100644
--- a/test/junit/scala/collection/VectorTest.scala
+++ b/test/junit/scala/collection/mutable/VectorTest.scala
diff --git a/test/junit/scala/issues/BytecodeTests.scala b/test/junit/scala/issues/BytecodeTests.scala
new file mode 100644
index 0000000000..7a05472277
--- /dev/null
+++ b/test/junit/scala/issues/BytecodeTests.scala
@@ -0,0 +1,39 @@
+package scala.issues
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+import scala.tools.asm.Opcodes
+import scala.tools.nsc.backend.jvm.CodeGenTools._
+import org.junit.Assert._
+import scala.collection.JavaConverters._
+import scala.tools.partest.ASMConverters._
+
+@RunWith(classOf[JUnit4])
+class BytecodeTests {
+ val compiler = newCompiler()
+
+ @Test
+ def t8731(): Unit = {
+ val code =
+ """class C {
+ | def f(x: Int) = (x: @annotation.switch) match {
+ | case 1 => 0
+ | case 2 => 1
+ | case 3 => 2
+ | }
+ | final val K = 10
+ | def g(x: Int) = (x: @annotation.switch) match {
+ | case K => 0
+ | case 1 => 10
+ | case 2 => 20
+ | }
+ |}
+ """.stripMargin
+
+ val List(c) = compileClasses(compiler)(code)
+
+ assertTrue(getSingleMethod(c, "f").instructions.count(_.isInstanceOf[TableSwitch]) == 1)
+ assertTrue(getSingleMethod(c, "g").instructions.count(_.isInstanceOf[LookupSwitch]) == 1)
+ }
+}
diff --git a/test/junit/scala/math/NumericTest.scala b/test/junit/scala/math/NumericTest.scala
index 4f0657f471..9bf7d4f1e4 100644
--- a/test/junit/scala/math/NumericTest.scala
+++ b/test/junit/scala/math/NumericTest.scala
@@ -1,4 +1,4 @@
-
+package scala.math
import org.junit.Assert._
import org.junit.Test
diff --git a/test/junit/scala/reflect/internal/PrintersTest.scala b/test/junit/scala/reflect/internal/PrintersTest.scala
index 1458b942dc..ca9b4671b2 100644
--- a/test/junit/scala/reflect/internal/PrintersTest.scala
+++ b/test/junit/scala/reflect/internal/PrintersTest.scala
@@ -24,10 +24,10 @@ object PrinterHelper {
resultCode.lines mkString s"$LF"
def assertResultCode(code: String)(parsedCode: String = "", typedCode: String = "", wrap: Boolean = false, printRoot: Boolean = false) = {
- def toolboxTree(tree: => Tree) = try{
+ def toolboxTree(tree: => Tree) = try {
tree
} catch {
- case e:scala.tools.reflect.ToolBoxError => throw new Exception(e.getMessage + ": " + code)
+ case e:scala.tools.reflect.ToolBoxError => throw new Exception(e.getMessage + ": " + code, e)
}
def wrapCode(source: String) = {
@@ -1186,4 +1186,4 @@ trait QuasiTreesPrintTests {
| };
| ()
|}""")
-} \ No newline at end of file
+}
diff --git a/test/junit/scala/reflect/internal/ScopeTest.scala b/test/junit/scala/reflect/internal/ScopeTest.scala
index 5166620189..1ab24facac 100644
--- a/test/junit/scala/reflect/internal/ScopeTest.scala
+++ b/test/junit/scala/reflect/internal/ScopeTest.scala
@@ -1,4 +1,4 @@
-package symtab
+package scala.reflect.internal
import scala.tools.nsc.symtab
diff --git a/test/junit/scala/reflect/internal/util/AbstractFileClassLoaderTest.scala b/test/junit/scala/reflect/internal/util/AbstractFileClassLoaderTest.scala
new file mode 100644
index 0000000000..a2537ddab7
--- /dev/null
+++ b/test/junit/scala/reflect/internal/util/AbstractFileClassLoaderTest.scala
@@ -0,0 +1,138 @@
+package scala.reflect.internal.util
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class AbstractFileClassLoaderTest {
+
+ import scala.reflect.io._
+ import scala.io.Source
+ import scala.io.Codec.UTF8
+ import scala.reflect.io.Streamable
+ import java.net.{ URLClassLoader, URL }
+
+ implicit def `we love utf8` = UTF8
+ implicit class `abs file ops`(f: AbstractFile) {
+ def writeContent(s: String): Unit = Streamable.closing(f.bufferedOutput)(os => os write s.getBytes(UTF8.charSet))
+ }
+ implicit class `url slurp`(url: URL) {
+ def slurp(): String = Streamable.slurp(url)
+ }
+
+ val NoClassLoader: ClassLoader = null
+
+ def fuzzBuzzBooz: (AbstractFile, AbstractFile) = {
+ val fuzz = new VirtualDirectory("fuzz", None)
+ val buzz = fuzz subdirectoryNamed "buzz"
+ val booz = buzz fileNamed "booz.class"
+ (fuzz, booz)
+ }
+
+ @Test
+ def afclGetsParent(): Unit = {
+ val p = new URLClassLoader(Array.empty[URL])
+ val d = new VirtualDirectory("vd", None)
+ val x = new AbstractFileClassLoader(d, p)
+ assertSame(p, x.getParent)
+ }
+
+ @Test
+ def afclGetsResource(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ val x = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val r = x.getResource("buzz/booz.class")
+ assertNotNull(r)
+ assertEquals("hello, world", r.slurp())
+ }
+
+ @Test
+ def afclGetsResourceFromParent(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ val (fuzz_, booz_) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ booz_ writeContent "hello, world_"
+ val p = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val x = new AbstractFileClassLoader(fuzz_, p)
+ val r = x.getResource("buzz/booz.class")
+ assertNotNull(r)
+ assertEquals("hello, world", r.slurp())
+ }
+
+ @Test
+ def afclGetsResourceInDefaultPackage(): Unit = {
+ val fuzz = new VirtualDirectory("fuzz", None)
+ val booz = fuzz fileNamed "booz.class"
+ val bass = fuzz fileNamed "bass"
+ booz writeContent "hello, world"
+ bass writeContent "lo tone"
+ val x = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val r = x.getResource("booz.class")
+ assertNotNull(r)
+ assertEquals("hello, world", r.slurp())
+ assertEquals("lo tone", (x getResource "bass").slurp())
+ }
+
+ // SI-8843
+ @Test
+ def afclGetsResources(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ val x = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val e = x.getResources("buzz/booz.class")
+ assertTrue(e.hasMoreElements)
+ assertEquals("hello, world", e.nextElement.slurp())
+ assertFalse(e.hasMoreElements)
+ }
+
+ @Test
+ def afclGetsResourcesFromParent(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ val (fuzz_, booz_) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ booz_ writeContent "hello, world_"
+ val p = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val x = new AbstractFileClassLoader(fuzz_, p)
+ val e = x.getResources("buzz/booz.class")
+ assertTrue(e.hasMoreElements)
+ assertEquals("hello, world", e.nextElement.slurp())
+ assertTrue(e.hasMoreElements)
+ assertEquals("hello, world_", e.nextElement.slurp())
+ assertFalse(e.hasMoreElements)
+ }
+
+ @Test
+ def afclGetsResourceAsStream(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ val x = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val r = x.getResourceAsStream("buzz/booz.class")
+ assertNotNull(r)
+ assertEquals("hello, world", Streamable.closing(r)(is => Source.fromInputStream(is).mkString))
+ }
+
+ @Test
+ def afclGetsClassBytes(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ val x = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val b = x.classBytes("buzz/booz.class")
+ assertEquals("hello, world", new String(b, UTF8.charSet))
+ }
+
+ @Test
+ def afclGetsClassBytesFromParent(): Unit = {
+ val (fuzz, booz) = fuzzBuzzBooz
+ val (fuzz_, booz_) = fuzzBuzzBooz
+ booz writeContent "hello, world"
+ booz_ writeContent "hello, world_"
+
+ val p = new AbstractFileClassLoader(fuzz, NoClassLoader)
+ val x = new AbstractFileClassLoader(fuzz_, p)
+ val b = x.classBytes("buzz/booz.class")
+ assertEquals("hello, world", new String(b, UTF8.charSet))
+ }
+}
diff --git a/test/junit/scala/tools/nsc/SampleTest.scala b/test/junit/scala/tools/nsc/SampleTest.scala
index 8e026da1ea..810c88ef9d 100644
--- a/test/junit/scala/tools/nsc/SampleTest.scala
+++ b/test/junit/scala/tools/nsc/SampleTest.scala
@@ -1,5 +1,4 @@
package scala.tools.nsc
-package test
import org.junit.Assert._
import org.junit.Test
diff --git a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
index 15bc1f427d..b892eb36cf 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala
@@ -76,4 +76,7 @@ object CodeGenTools {
def assertSameCode(actual: List[Instruction], expected: List[Instruction]): Unit = {
assertTrue(s"\nExpected: $expected\nActual : $actual", actual === expected)
}
+
+ def getSingleMethod(classNode: ClassNode, name: String): Method =
+ convertMethod(classNode.methods.asScala.toList.find(_.name == name).get)
}
diff --git a/test/junit/scala/util/t7265.scala b/test/junit/scala/util/SpecVersionTest.scala
index 71f085d21d..e3e7a978f2 100644
--- a/test/junit/scala/util/t7265.scala
+++ b/test/junit/scala/util/SpecVersionTest.scala
@@ -1,14 +1,11 @@
package scala.util
-package test
import org.junit.Assert._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import scala.util.PropertiesTrait
-
/** The java version property uses the spec version
* and must work for all "major.minor" and fail otherwise.
*/
@@ -24,6 +21,7 @@ class SpecVersionTest {
override lazy val scalaProps = new java.util.Properties
}
+ // SI-7265
@Test
def comparesCorrectly(): Unit = {
assert(sut isJavaAtLeast "1.5")
diff --git a/test/junit/scala/util/matching/regextract-char.scala b/test/junit/scala/util/matching/CharRegexTest.scala
index 50fdcd9d46..50fdcd9d46 100644
--- a/test/junit/scala/util/matching/regextract-char.scala
+++ b/test/junit/scala/util/matching/CharRegexTest.scala