Skip to content

Commit

Permalink
Merge branch '2.13.x' into topic/safe-iterators-2/PR
Browse files Browse the repository at this point in the history
  • Loading branch information
NthPortal committed Oct 22, 2020
2 parents 04c7e4b + 9c75e62 commit 6bf5580
Show file tree
Hide file tree
Showing 45 changed files with 267 additions and 79 deletions.
8 changes: 3 additions & 5 deletions src/compiler/scala/tools/nsc/javac/JavaScanners.scala
Expand Up @@ -213,12 +213,10 @@ trait JavaScanners extends ast.parser.ScannersCommon {
case SLASHEQ => "`/=`"
case TILDE => "`~`"
case _ =>
try ("`" + tokenName(token) + "'")
try s"`${tokenName(token)}`"
catch {
case _: ArrayIndexOutOfBoundsException =>
"`<" + token + ">'"
case _: NullPointerException =>
"`<(" + token + ")>'"
case _: ArrayIndexOutOfBoundsException => s"`<$token>`"
case _: NullPointerException => s"`<($token)>`"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Expand Up @@ -271,7 +271,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
val YcacheMacroClassLoader = CachePolicy.setting("macro", "macros")
val YmacroClasspath = PathSetting ("-Ymacro-classpath", "The classpath used to reflectively load macro implementations, default is the compilation classpath.", "")

val Youtline = BooleanSetting ("-Youtline", "Don't compile method bodies. Use together with `-Ystop-after:pickler to generate the pickled signatures for all source files.").internalOnly()
val Youtline = BooleanSetting ("-Youtline", "Don't compile method bodies. Use together with `-Ystop-after:pickler` to generate the pickled signatures for all source files.").internalOnly()

val exposeEmptyPackage = BooleanSetting ("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly()
val Ydelambdafy = ChoiceSetting ("-Ydelambdafy", "strategy", "Strategy used for translating lambdas into JVM code.", List("inline", "method"), "method")
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
Expand Up @@ -1346,10 +1346,10 @@ trait ContextErrors {
"`override` modifier not allowed for constructors"

case AbstractOverride =>
"`abstract override' modifier only allowed for members of traits"
"`abstract override` modifier only allowed for members of traits"

case AbstractOverrideOnTypeMember =>
"`abstract override' modifier not allowed for type members"
"`abstract override` modifier not allowed for type members"

case LazyAndEarlyInit =>
"`lazy` definitions may not be initialized early"
Expand Down
47 changes: 31 additions & 16 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Expand Up @@ -712,7 +712,7 @@ trait Contexts { self: Analyzer =>
c(TypeConstructorAllowed) = false

registerContext(c.asInstanceOf[analyzer.Context])
debuglog("[context] ++ " + c.unit + " / " + (if (tree == null) "" else tree.summaryString))
debuglog(s"[context] ++ ${c.unit} / ${if (tree == null) "" else tree.summaryString}")
c
}

Expand Down Expand Up @@ -1499,26 +1499,41 @@ trait Contexts { self: Analyzer =>
* as the reference, have lowest precedence. Also "root" imports added implicitly.
*/
def foreignDefined = defSym.exists && thisContext.isPackageOwnedInDifferentUnit(defSym) // SI-2458
// can an import at this depth possibly shadow the definition found in scope if any?
def importCanShadowAtDepth(imp: ImportInfo) = imp.depth > symbolDepth || (
if (thisContext.unit.isJava) imp.depth == symbolDepth && imp.isExplicitImport(name)
else foreignDefined
)

while (!impSym.exists && importCursor.imp1Exists && importCanShadowAtDepth(importCursor.imp1)) {
val (sel, sym) = lookupImport(imp1, requireExplicit = false)
impSel = sel
impSym = sym
if (!impSym.exists)
importCursor.advanceImp1Imp2()
// Find the first candidate import
def advanceCursorToNextImport(): Unit = {
val defIsLevel4 = foreignDefined
// can the import at this depth compete with the definition?
// If not, we can stop inspecting outer scopes (including more imports).
// A competing import can either shadow the definition or render it ambiguous.
//
@inline def importCanShadowAtDepth(imp: ImportInfo) = {
@inline def importCompetesWithDefinition =
if (thisContext.unit.isJava) imp.depth == symbolDepth && defIsLevel4
else defIsLevel4
imp.depth > symbolDepth || importCompetesWithDefinition
}

while (!impSym.exists && importCursor.imp1Exists && importCanShadowAtDepth(importCursor.imp1)) {
val javaRule = thisContext.unit.isJava && defIsLevel4
val (sel, sym) = lookupImport(imp1, requireExplicit = javaRule)
impSel = sel
impSym = sym
if (!impSym.exists)
importCursor.advanceImp1Imp2()
}
}
advanceCursorToNextImport()

val preferDef: Boolean = defSym.exists && (!impSym.exists || {
// 4) root imported symbols have same (lowest) precedence as package-owned symbols in different compilation units.
if (imp1.depth < symbolDepth && imp1.isRootImport && foreignDefined)
true
// 4) imported symbols have higher precedence than package-owned symbols in different compilation units.
else if (imp1.depth >= symbolDepth && foreignDefined)
// except that in Java, the import must be "explicit" (level 2)
else if (thisContext.unit.isJava && imp1.depth == symbolDepth && foreignDefined)
!importCursor.imp1Explicit
else if (!thisContext.unit.isJava && imp1.depth >= symbolDepth && foreignDefined)
false
// Defined symbols take precedence over erroneous imports.
else if (impSym.isError || impSym.name == nme.CONSTRUCTOR)
Expand All @@ -1531,8 +1546,8 @@ trait Contexts { self: Analyzer =>
return ambiguousDefnAndImport(defSym.alternatives.head.owner, imp1)
})

// If the defSym is at 4, and there is a def at 1 in scope, then the reference is ambiguous.
if (foreignDefined && !defSym.isPackage) {
// If the defSym is at 4, and there is a def at 1 in scope due to packaging, then the reference is ambiguous.
if (foreignDefined && !defSym.isPackage && !thisContext.unit.isJava) {
val defSym0 = defSym
val pre0 = pre
val cx0 = cx
Expand Down Expand Up @@ -1919,7 +1934,7 @@ trait Contexts { self: Analyzer =>
def sameDepth: Boolean = imp1.depth == imp2.depth

private def imp2Exists = imp2Ctx.importOrNull != null
private def imp1Explicit = imp1 isExplicitImport name
def imp1Explicit = imp1 isExplicitImport name
private def imp2Explicit = imp2 isExplicitImport name
}

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Expand Up @@ -403,7 +403,7 @@ abstract class RefChecks extends Transform {
if (!(memberOverrides || other.isDeferred) && !member.isSynthetic) {
overrideErrorConcreteMissingOverride()
} else if (other.isAbstractOverride && other.isIncompleteIn(clazz) && !member.isAbstractOverride) {
overrideErrorWithMemberInfo("`abstract override' modifiers required to override:")
overrideErrorWithMemberInfo("`abstract override` modifiers required to override:")
}
else if (memberOverrides && (other hasFlag ACCESSOR) && !(other hasFlag STABLE | DEFERRED)) {
// TODO: this is not covered by the spec.
Expand All @@ -414,7 +414,7 @@ abstract class RefChecks extends Transform {
!member.isDeferred && !other.isDeferred &&
intersectionIsEmpty(member.extendedOverriddenSymbols, other.extendedOverriddenSymbols)) {
overrideErrorWithMemberInfo("cannot override a concrete member without a third member that's overridden by both " +
"(this rule is designed to prevent ``accidental overrides'')")
"(this rule is designed to prevent accidental overrides)")
} else if (other.isStable && !member.isStable) { // (1.4)
overrideErrorWithMemberInfo("stable, immutable value required to override:")
} else if (member.isValue && member.isLazy &&
Expand Down Expand Up @@ -1775,7 +1775,7 @@ abstract class RefChecks extends Transform {
tree

case treeInfo.WildcardStarArg(_) if !isRepeatedParamArg(tree) =>
reporter.error(tree.pos, "no `: _*' annotation allowed here\n"+
reporter.error(tree.pos, "no `: _*` annotation allowed here\n"+
"(such annotations are only allowed in arguments to *-parameters)")
tree

Expand Down
15 changes: 15 additions & 0 deletions src/library/scala/collection/Factory.scala
Expand Up @@ -383,14 +383,29 @@ trait SpecificIterableFactory[-A, +C] extends Factory[A, C] {
*/
trait MapFactory[+CC[_, _]] extends Serializable {

/**
* An empty Map
*/
def empty[K, V]: CC[K, V]

/**
* A collection of type Map generated from given iterable object.
*/
def from[K, V](it: IterableOnce[(K, V)]): CC[K, V]

/**
* A collection of type Map that contains given key/value bindings.
*/
def apply[K, V](elems: (K, V)*): CC[K, V] = from(elems)

/**
* The default builder for Map objects.
*/
def newBuilder[K, V]: Builder[(K, V), CC[K, V]]

/**
* The default Factory instance for maps.
*/
implicit def mapFactory[K, V]: Factory[(K, V), CC[K, V]] = MapFactory.toFactory(this)
}

Expand Down
11 changes: 0 additions & 11 deletions src/library/scala/collection/StringOps.scala
Expand Up @@ -1443,7 +1443,6 @@ final class StringOps(private val s: String) extends AnyVal {
* ''n'' times in `that`, then the first ''n'' occurrences of `x` will not form
* part of the result, but any following occurrences will.
*/
@deprecated("Use `s.toSeq.diff(...).unwrap` instead of `s.diff(...)`", "2.13.0")
def diff[B >: Char](that: Seq[B]): String = new WrappedString(s).diff(that).unwrap

/** Computes the multiset intersection between this string and another sequence.
Expand All @@ -1455,11 +1454,9 @@ final class StringOps(private val s: String) extends AnyVal {
* ''n'' times in `that`, then the first ''n'' occurrences of `x` will be retained
* in the result, but any following occurrences will be omitted.
*/
@deprecated("Use `s.toSeq.intersect(...).unwrap` instead of `s.intersect(...)`", "2.13.0")
def intersect[B >: Char](that: Seq[B]): String = new WrappedString(s).intersect(that).unwrap

/** Selects all distinct chars of this string ignoring the duplicates. */
@deprecated("Use `s.toSeq.distinct.unwrap` instead of `s.distinct`", "2.13.0")
def distinct: String = new WrappedString(s).distinct.unwrap

/** Selects all distinct chars of this string ignoring the duplicates as determined by `==` after applying
Expand All @@ -1469,7 +1466,6 @@ final class StringOps(private val s: String) extends AnyVal {
* @tparam B the type of the elements after being transformed by `f`
* @return a new string consisting of all the chars of this string without duplicates.
*/
@deprecated("Use `s.toSeq.distinctBy(...).unwrap` instead of `s.distinctBy(...)`", "2.13.0")
def distinctBy[B](f: Char => B): String = new WrappedString(s).distinctBy(f).unwrap

/** Sorts the characters of this string according to an Ordering.
Expand All @@ -1483,7 +1479,6 @@ final class StringOps(private val s: String) extends AnyVal {
* @return a string consisting of the chars of this string
* sorted according to the ordering `ord`.
*/
@deprecated("Use `s.toSeq.sorted.unwrap` instead of `s.sorted`", "2.13.0")
def sorted[B >: Char](implicit ord: Ordering[B]): String = new WrappedString(s).sorted(ord).unwrap

/** Sorts this string according to a comparison function.
Expand All @@ -1497,7 +1492,6 @@ final class StringOps(private val s: String) extends AnyVal {
* @return a string consisting of the elements of this string
* sorted according to the comparison function `lt`.
*/
@deprecated("Use `s.toSeq.sortWith(...).unwrap` instead of `s.sortWith(...)`", "2.13.0")
def sortWith(lt: (Char, Char) => Boolean): String = new WrappedString(s).sortWith(lt).unwrap

/** Sorts this string according to the Ordering which results from transforming
Expand All @@ -1516,7 +1510,6 @@ final class StringOps(private val s: String) extends AnyVal {
* sorted according to the ordering where `x < y` if
* `ord.lt(f(x), f(y))`.
*/
@deprecated("Use `s.toSeq.sortBy(...).unwrap` instead of `s.sortBy(...)`", "2.13.0")
def sortBy[B](f: Char => B)(implicit ord: Ordering[B]): String = new WrappedString(s).sortBy(f)(ord).unwrap

/** Partitions this string into a map of strings according to some discriminator function.
Expand All @@ -1531,7 +1524,6 @@ final class StringOps(private val s: String) extends AnyVal {
* for which `f(x)` equals `k`.
*
*/
@deprecated("Use `s.toSeq.groupBy(...).view.mapValues(_.unwrap)` instead of `s.groupBy(...)`", "2.13.0")
def groupBy[K](f: Char => K): immutable.Map[K, String] = new WrappedString(s).groupBy(f).view.mapValues(_.unwrap).toMap

/** Groups chars in fixed size blocks by passing a "sliding window"
Expand All @@ -1544,7 +1536,6 @@ final class StringOps(private val s: String) extends AnyVal {
* last element (which may be the only element) will be truncated
* if there are fewer than `size` chars remaining to be grouped.
*/
@deprecated("Use `s.toSeq.sliding(...).map(_.unwrap)` instead of `s.sliding(...)`", "2.13.0")
def sliding(size: Int, step: Int = 1): Iterator[String] = new WrappedString(s).sliding(size, step).map(_.unwrap)

/** Iterates over combinations. A _combination_ of length `n` is a subsequence of
Expand All @@ -1560,15 +1551,13 @@ final class StringOps(private val s: String) extends AnyVal {
* @return An Iterator which traverses the possible n-element combinations of this string.
* @example `"abbbc".combinations(2) = Iterator(ab, ac, bb, bc)`
*/
@deprecated("Use `s.toSeq.combinations(...).map(_.unwrap)` instead of `s.combinations(...)`", "2.13.0")
def combinations(n: Int): Iterator[String] = new WrappedString(s).combinations(n).map(_.unwrap)

/** Iterates over distinct permutations.
*
* @return An Iterator which traverses the distinct permutations of this string.
* @example `"abb".permutations = Iterator(abb, bab, bba)`
*/
@deprecated("Use `s.toSeq.permutations(...).map(_.unwrap)` instead of `s.permutations(...)`", "2.13.0")
def permutations: Iterator[String] = new WrappedString(s).permutations.map(_.unwrap)
}

Expand Down
6 changes: 6 additions & 0 deletions src/library/scala/collection/immutable/ListMap.scala
Expand Up @@ -107,6 +107,7 @@ sealed class ListMap[K, +V]
private[immutable] def value: V = throw new NoSuchElementException("value of empty map")
private[immutable] def next: ListMap[K, V] = throw new NoSuchElementException("next of empty map")

override def foldRight[Z](z: Z)(op: ((K, V), Z) => Z): Z = ListMap.foldRightInternal(this, z, op)
override protected[this] def className = "ListMap"

}
Expand Down Expand Up @@ -272,6 +273,11 @@ object ListMap extends MapFactory[ListMap] {
* @tparam V the map value type
*/
def newBuilder[K, V]: ReusableBuilder[(K, V), ListMap[K, V]] = new ListMapBuilder[K, V]

@tailrec private def foldRightInternal[K, V, Z](map: ListMap[K, V], prevValue: Z, op: ((K, V), Z) => Z): Z = {
if (map.isEmpty) prevValue
else foldRightInternal(map.init, op(map.last, prevValue), op)
}
}

/** Builder for ListMap.
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/ArrayBuffer.scala
Expand Up @@ -104,7 +104,7 @@ class ArrayBuffer[A] private (initialElements: Array[AnyRef], initialSize: Int)

@inline private def checkWithinBounds(lo: Int, hi: Int) = {
if (lo < 0) throw new IndexOutOfBoundsException(s"$lo is out of bounds (min 0, max ${size0-1})")
if (hi > size0) throw new IndexOutOfBoundsException(s"$hi is out of bounds (min 0, max ${size0 - 1})")
if (hi > size0) throw new IndexOutOfBoundsException(s"${hi - 1} is out of bounds (min 0, max ${size0 - 1})")
}

def apply(n: Int): A = {
Expand Down
Expand Up @@ -227,7 +227,7 @@ class ReplReporterImpl(val config: ShellConfig, val settings: Settings = new Set
}

override def rerunWithDetails(setting: reflect.internal.settings.MutableSettings#Setting, name: String): String =
s"; for details, enable `:setting $name' or `:replay $name'"
s"; for details, enable `:setting $name` or `:replay $name`"

override def finish() = {
if (hasWarnings) printMessage(s"${StringOps.countElementsAsString(warningCount, label(WARNING))} found")
Expand Down
4 changes: 2 additions & 2 deletions test/files/jvm/interpreter.check
Expand Up @@ -87,7 +87,7 @@ scala> case class Bar(n: Int)
class Bar

scala> implicit def foo2bar(foo: Foo) = Bar(foo.n)
warning: 1 feature warning; for details, enable `:setting -feature' or `:replay -feature'
warning: 1 feature warning; for details, enable `:setting -feature` or `:replay -feature`
def foo2bar(foo: Foo): Bar

scala> val bar: Bar = Foo(3)
Expand Down Expand Up @@ -261,7 +261,7 @@ scala> xs map (x => x)
val res6: Array[_] = Array(1, 2)

scala> xs map (x => (x, x))
warning: 1 feature warning; for details, enable `:setting -feature' or `:replay -feature'
warning: 1 feature warning; for details, enable `:setting -feature` or `:replay -feature`
val res7: Array[(_$1, _$1)] forSome { type _$1 } = Array((1,1), (2,2))

scala>
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/sd128.check
Expand Up @@ -4,7 +4,7 @@ Test.scala:4: error: class C1 inherits conflicting members:
(note: this can be resolved by declaring an `override` in class C1.)
class C1 extends A with T // error
^
Test.scala:5: error: cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent ``accidental overrides'')
Test.scala:5: error: cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent accidental overrides)
def f: Int (defined in trait T)
with <defaultmethod> def f(): Int (defined in trait A)
class C2 extends T with A // error
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t2497.check
@@ -1,4 +1,4 @@
t2497.scala:21: error: cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent ``accidental overrides'')
t2497.scala:21: error: cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent accidental overrides)
def eval: Int (defined in class Foo)
with absoverride def eval: Int (defined in trait DebugNode)
(new Foo with DebugNode).eval
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t2497b.check
@@ -1,4 +1,4 @@
t2497b.scala:6: error: cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent ``accidental overrides'')
t2497b.scala:6: error: cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent accidental overrides)
def f: Int (defined in trait B)
with override def f: Int (defined in trait AAA)
class C extends B with AAA
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t6795.check
@@ -1,4 +1,4 @@
t6795.scala:3: error: `abstract override' modifier not allowed for type members
t6795.scala:3: error: `abstract override` modifier not allowed for type members
trait T1 extends T { abstract override type U = Int }
^
1 error
4 changes: 2 additions & 2 deletions test/files/neg/t835.check
@@ -1,8 +1,8 @@
t835.scala:2: error: no `: _*' annotation allowed here
t835.scala:2: error: no `: _*` annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
Console.println(List(List(1, 2, 3) : _*, List(4, 5, 6) : _*))
^
t835.scala:2: error: no `: _*' annotation allowed here
t835.scala:2: error: no `: _*` annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
Console.println(List(List(1, 2, 3) : _*, List(4, 5, 6) : _*))
^
Expand Down
8 changes: 4 additions & 4 deletions test/files/neg/t875.check
@@ -1,16 +1,16 @@
t875.scala:3: error: no `: _*' annotation allowed here
t875.scala:3: error: no `: _*` annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
val ys = List(1, 2, 3, xs: _*)
^
t875.scala:6: error: no `: _*' annotation allowed here
t875.scala:6: error: no `: _*` annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
mkList1(xs: _*)
^
t875.scala:15: error: no `: _*' annotation allowed here
t875.scala:15: error: no `: _*` annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
f(true, 1, xs: _*)
^
t875.scala:16: error: no `: _*' annotation allowed here
t875.scala:16: error: no `: _*` annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
g(1, xs:_*)
^
Expand Down

0 comments on commit 6bf5580

Please sign in to comment.