Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.13.x' into merge-2.12-to-2.13-…
Browse files Browse the repository at this point in the history
…jun-19
  • Loading branch information
SethTisue committed Jun 23, 2020
2 parents d837765 + f5cca6f commit 88651a0
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 94 deletions.
54 changes: 54 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,60 @@ val mimaFilterSettings = Seq {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.runtime.Settings.async"),

ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.api.Internals#InternalApi.markForAsyncTransform"),

// Fix for scala/bug#11976
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.filterImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.strictOptimizedCollect"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.strictOptimizedConcat"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.strictOptimizedFlatMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.strictOptimizedFlatten"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.strictOptimizedMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#AbstractJMapWrapper.strictOptimizedZip"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.filterImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.strictOptimizedCollect"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.strictOptimizedConcat"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.strictOptimizedFlatMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.strictOptimizedFlatten"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.strictOptimizedMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JCollectionWrapper.strictOptimizedZip"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.filterImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.strictOptimizedCollect"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.strictOptimizedConcat"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.strictOptimizedFlatMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.strictOptimizedFlatten"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.strictOptimizedMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JIterableWrapper.strictOptimizedZip"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.filterImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.strictOptimizedCollect"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.strictOptimizedConcat"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.strictOptimizedFlatMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.strictOptimizedFlatten"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.strictOptimizedMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JListWrapper.strictOptimizedZip"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.filterImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.strictOptimizedCollect"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.strictOptimizedConcat"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.strictOptimizedFlatMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.strictOptimizedFlatten"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.strictOptimizedMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JPropertiesWrapper.strictOptimizedZip"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.filterImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.strictOptimizedCollect"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.strictOptimizedConcat"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.strictOptimizedFlatMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.strictOptimizedFlatten"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.strictOptimizedMap"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#JSetWrapper.strictOptimizedZip"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$AbstractJMapWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JCollectionWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JConcurrentMapWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JIterableWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JListWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JMapWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JMapWrapperLike"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JPropertiesWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$JSetWrapper"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.mutable.WeakHashMap"),
),
}

Expand Down
19 changes: 6 additions & 13 deletions src/compiler/scala/tools/nsc/typechecker/Namers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1890,19 +1890,12 @@ trait Namers extends MethodSynthesis {
def annotSig(annotations: List[Tree], annotee: Tree, pred: AnnotationInfo => Boolean): List[AnnotationInfo] =
annotations filterNot (_ eq null) map { ann =>
val ctx = typer.context
// enteringTyper to allow inferView in annotation args, scala/bug#5892
def createAnnotationInfo = enteringTyper {
val annotSig = newTyper(ctx.makeNonSilent(ann)).typedAnnotation(ann, Some(annotee))
if (pred(annotSig)) annotSig else UnmappableAnnotation // UnmappableAnnotation will be dropped in typedValDef and typedDefDef
}

ann match {
case Apply(_, Nil) =>
// zero-argument annotations can be computed eagerly, see also TreeInfo.isUncheckedStable
createAnnotationInfo
case _ =>
// need to be lazy, scala/bug#1782
AnnotationInfo lazily createAnnotationInfo
// need to be lazy, #1782. enteringTyper to allow inferView in annotation args, scala/bug#5892.
AnnotationInfo lazily {
enteringTyper {
val annotSig = newTyper(ctx.makeNonSilent(ann)).typedAnnotation(ann, Some(annotee))
if (pred(annotSig)) annotSig else UnmappableAnnotation // UnmappableAnnotation will be dropped in typedValDef and typedDefDef
}
}
}

Expand Down
33 changes: 26 additions & 7 deletions src/library/scala/collection/convert/JavaCollectionWrappers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ private[collection] object JavaCollectionWrappers extends Serializable {
case class IterableWrapper[A](underlying: Iterable[A]) extends ju.AbstractCollection[A] with IterableWrapperTrait[A] with Serializable

@SerialVersionUID(3L)
case class JIterableWrapper[A](underlying: jl.Iterable[A]) extends AbstractIterable[A] with Serializable {
case class JIterableWrapper[A](underlying: jl.Iterable[A])
extends AbstractIterable[A]
with StrictOptimizedIterableOps[A, Iterable, Iterable[A]]
with Serializable {
def iterator = underlying.iterator.asScala
override def iterableFactory = mutable.ArrayBuffer
override def isEmpty: Boolean = !underlying.iterator().hasNext
}

@SerialVersionUID(3L)
case class JCollectionWrapper[A](underlying: ju.Collection[A]) extends AbstractIterable[A] with Serializable {
case class JCollectionWrapper[A](underlying: ju.Collection[A])
extends AbstractIterable[A]
with StrictOptimizedIterableOps[A, Iterable, Iterable[A]]
with Serializable {
def iterator = underlying.iterator.asScala
override def size = underlying.size
override def knownSize: Int = if (underlying.isEmpty) 0 else super.knownSize
Expand Down Expand Up @@ -94,8 +100,10 @@ private[collection] object JavaCollectionWrappers extends Serializable {
}

@SerialVersionUID(3L)
case class JListWrapper[A](underlying: ju.List[A]) extends mutable.AbstractBuffer[A]
case class JListWrapper[A](underlying: ju.List[A])
extends mutable.AbstractBuffer[A]
with SeqOps[A, mutable.Buffer, mutable.Buffer[A]]
with StrictOptimizedSeqOps[A, mutable.Buffer, mutable.Buffer[A]]
with IterableFactoryDefaults[A, mutable.Buffer]
with Serializable {
def length = underlying.size
Expand Down Expand Up @@ -169,7 +177,11 @@ private[collection] object JavaCollectionWrappers extends Serializable {
}

@SerialVersionUID(3L)
case class JSetWrapper[A](underlying: ju.Set[A]) extends mutable.AbstractSet[A] with mutable.SetOps[A, mutable.Set, mutable.Set[A]] with Serializable {
case class JSetWrapper[A](underlying: ju.Set[A])
extends mutable.AbstractSet[A]
with mutable.SetOps[A, mutable.Set, mutable.Set[A]]
with StrictOptimizedSetOps[A, mutable.Set, mutable.Set[A]]
with Serializable {

override def size: Int = underlying.size
override def isEmpty: Boolean = underlying.isEmpty
Expand Down Expand Up @@ -299,7 +311,9 @@ private[collection] object JavaCollectionWrappers extends Serializable {
with JMapWrapperLike[K, V, mutable.Map, mutable.Map[K, V]] with Serializable

trait JMapWrapperLike[K, V, +CC[X, Y] <: mutable.MapOps[X, Y, CC, _], +C <: mutable.MapOps[K, V, CC, C]]
extends mutable.MapOps[K, V, CC, C] {
extends mutable.MapOps[K, V, CC, C]
with StrictOptimizedMapOps[K, V, CC, C]
with StrictOptimizedIterableOps[(K, V), mutable.Iterable, C] {

def underlying: ju.Map[K, V]

Expand Down Expand Up @@ -458,8 +472,13 @@ private[collection] object JavaCollectionWrappers extends Serializable {
}

@SerialVersionUID(3L)
case class JPropertiesWrapper(underlying: ju.Properties) extends mutable.AbstractMap[String, String]
with mutable.MapOps[String, String, mutable.Map, mutable.Map[String, String]] with Serializable {
case class JPropertiesWrapper(underlying: ju.Properties)
extends mutable.AbstractMap[String, String]
with mutable.MapOps[String, String, mutable.Map, mutable.Map[String, String]]
with StrictOptimizedMapOps[String, String, mutable.Map, mutable.Map[String, String]]
with StrictOptimizedIterableOps[(String, String), mutable.Iterable, mutable.Map[String, String]]
with Serializable {
unzip

override def size = underlying.size
override def isEmpty: Boolean = underlying.isEmpty
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/immutable/IntMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ sealed abstract class IntMap[+T] extends AbstractMap[Int, T]

override protected[this] def className = "IntMap"

override def isEmpty = this == IntMap.Nil
override def isEmpty = this eq IntMap.Nil
override def knownSize: Int = if (isEmpty) 0 else super.knownSize
override def filter(f: ((Int, T)) => Boolean): IntMap[T] = this match {
case IntMap.Bin(prefix, mask, left, right) => {
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/immutable/LongMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ sealed abstract class LongMap[+T] extends AbstractMap[Long, T]

override protected[this] def className = "LongMap"

override def isEmpty = this == LongMap.Nil
override def isEmpty = this eq LongMap.Nil
override def knownSize: Int = if (isEmpty) 0 else super.knownSize
override def filter(f: ((Long, T)) => Boolean): LongMap[T] = this match {
case LongMap.Bin(prefix, mask, left, right) => {
Expand Down
4 changes: 1 addition & 3 deletions src/reflect/scala/reflect/internal/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ abstract class TreeInfo {
private def symOk(sym: Symbol) = sym != null && !sym.isError && sym != NoSymbol
private def typeOk(tp: Type) = tp != null && ! tp.isError

private def isUncheckedStable(sym: Symbol) =
// zero-arg annotations (like @uncheckedStable) are created eagerly. avoid forcing all annotations (scala/bug#11870).
sym.isTerm && sym.annotations.exists(ann => ann.isInstanceOf[CompleteAnnotationInfo] && ann.symbol == uncheckedStableClass)
private def isUncheckedStable(sym: Symbol) = sym.isTerm && sym.hasAnnotation(uncheckedStableClass)

/** Assuming `sym` is a member of `tree`, is it a "stable member"?
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ trait PresentationCompilation { self: IMain =>
import CompletionResult.NoResults

def isMemberDeprecated(m: Member) = m match {
case tm: TypeMember if tm.viaView.isDeprecated || tm.viaView != NoSymbol && tm.viaView.owner.isDeprecated || !m.sym.exists =>
case tm: TypeMember if tm.viaView.isDeprecated || tm.viaView != NoSymbol && tm.viaView.owner.isDeprecated =>
true
case _ =>
m.sym.isDeprecated ||
Expand Down
12 changes: 12 additions & 0 deletions src/testkit/scala/tools/testkit/AssertUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ object AssertUtil {
def readyOrNot(awaitable: Awaitable[_]): Boolean = Try(Await.ready(awaitable, TestDuration.Standard)).isSuccess

def withoutATrace[A](body: => A) = NoTrace(body)

private lazy val modsField = classOf[Field].getDeclaredField("modifiers").tap(_.setAccessible(true))

def getFieldAccessible[T: ClassTag](n: String): Field =
implicitly[ClassTag[T]]
.runtimeClass.getDeclaredField(n)
.tap { f =>
if ((f.getModifiers & Modifier.FINAL) != 0)
modsField.setInt(f, f.getModifiers() & ~Modifier.FINAL)
if ((f.getModifiers & Modifier.PUBLIC) == 0)
f.setAccessible(true)
}
}

object TestDuration {
Expand Down
60 changes: 0 additions & 60 deletions test/files/pos/t11870.scala

This file was deleted.

12 changes: 12 additions & 0 deletions test/junit/scala/collection/CollectionConversionsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,17 @@ class CollectionConversionsTest {
fail("Not all tests successful")
}
}

@Test
def t11976(): Unit = {
import scala.jdk.CollectionConverters._
val myMap_1 = java.util.Collections.singletonMap("a", 1)
var x = 0
myMap_1.asScala.partition { case (key, value) =>
x += 1
true
}
assertEquals(1, x)
}
}

31 changes: 31 additions & 0 deletions test/junit/scala/collection/immutable/IntMapTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.immutable

import org.junit.Assert._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

import scala.tools.testkit.AssertUtil.{getFieldAccessible => f}

@RunWith(classOf[JUnit4])
class IntMapTest {
@Test
def `isEmpty O(1)`(): Unit = {
val m = IntMap(1 -> (), 2 -> (), 3 -> ())
f[IntMap.Bin[_]]("left").set(m, null)
f[IntMap.Bin[_]]("right").set(m, null)
assertFalse(m.isEmpty) // no NPE, does not access left or right
}
}
32 changes: 32 additions & 0 deletions test/junit/scala/collection/immutable/LongMapTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.immutable

import org.junit.Assert._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

import scala.tools.testkit.AssertUtil.{getFieldAccessible => f}

@RunWith(classOf[JUnit4])
class LongMapTest {

@Test
def `isEmpty O(1)`(): Unit = {
val m = LongMap(1L -> (), 2L -> (), 3L -> ())
f[LongMap.Bin[_]]("left").set(m, null)
f[LongMap.Bin[_]]("right").set(m, null)
assertFalse(m.isEmpty) // no NPE, does not access left or right
}
}
Loading

0 comments on commit 88651a0

Please sign in to comment.