Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build library under -Xsource:3 [ci: last-only] #10551

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ lazy val library = configureAsSubproject(project)
name := "scala-library",
description := "Scala Standard Library",
Compile / scalacOptions ++= Seq("-sourcepath", (Compile / scalaSource).value.toString),
Compile / scalacOptions ++= Seq("-Xlint", "-feature"),
Compile / scalacOptions ++= Seq("-Xlint", "-feature", "-Xsource:3"),
Compile / scalacOptions ++= Seq("-Wconf:cat=scala3-migration&msg=elidable&site=scala.Predef:s"),
Compile / scalacOptions ++= Seq("-Wconf:cat=scala3-migration&msg=constructor modifiers&site=scala.concurrent.duration.Deadline:s"), // for bootstrap until restarr
Compile / doc / scalacOptions ++= {
val libraryAuxDir = (ThisBuild / baseDirectory).value / "src/library-aux"
Seq(
Expand Down
14 changes: 11 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3303,7 +3303,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
def typedStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
val inBlock = exprOwner == context.owner
def includesTargetPos(tree: Tree) =
tree.pos.isRange && context.unit.exists && (tree.pos includes context.unit.targetPos)
tree.pos.isRange && context.unit.exists && tree.pos.includes(context.unit.targetPos)
val localTarget = stats exists includesTargetPos
def typedStat(stat: Tree): Tree = stat match {
case s if context.owner.isRefinementClass && !treeInfo.isDeclarationOrTypeDef(s) => OnlyDeclarationsError(s)
Expand Down Expand Up @@ -3418,8 +3418,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// OPT: shouldAdd is usually true. Call it here, rather than in the outer loop
case Some(tree) if shouldAdd(sym) =>
// if the completer set the IS_ERROR flag, retract the stat (currently only used by applyUnapplyMethodCompleter)
if (!sym.initialize.hasFlag(IS_ERROR))
newStats += typedStat(tree) // might add even more synthetics to the scope
if (!sym.initialize.hasFlag(IS_ERROR)) {
val newStat = typedStat(tree)
if (currentRun.isScala3 && !sym.owner.isCaseClass)
tree match {
case DefDef(mods, nme.apply, _, _, _, _) if mods.hasFlag(PRIVATE) || mods.privateWithin != tpnme.EMPTY =>
runReporting.warning(tree.pos, "access modifiers for `apply` method are copied from the case class constructor", WarningCategory.Scala3Migration, sym)
case _ =>
}
newStats += newStat // might add even more synthetics to the scope
}
context.unit.synthetics -= sym
case _ => ()
}
Expand Down
6 changes: 1 addition & 5 deletions src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ trait Unapplies extends ast.TreeDSL {
val mods =
if (applyShouldInheritAccess(inheritedMods))
(caseMods | (inheritedMods.flags & PRIVATE)).copy(privateWithin = inheritedMods.privateWithin)
.tap { mods =>
if (currentRun.isScala3 && mods != caseMods)
runReporting.warning(cdef.pos, "constructor modifiers are assumed by synthetic `apply` method", WarningCategory.Scala3Migration, cdef.symbol)
}
else
caseMods
factoryMeth(mods, nme.apply, cdef)
Expand Down Expand Up @@ -282,7 +278,7 @@ trait Unapplies extends ast.TreeDSL {
Modifiers(SYNTHETIC | (inheritedMods.flags & AccessFlags), inheritedMods.privateWithin)
.tap { mods =>
if (currentRun.isScala3 && mods != Modifiers(SYNTHETIC))
runReporting.warning(cdef.pos, "constructor modifiers are assumed by synthetic `copy` method", WarningCategory.Scala3Migration, cdef.symbol)
runReporting.warning(cdef.pos, "access modifiers for `copy` method are copied from the case class constructor", WarningCategory.Scala3Migration, cdef.symbol)
}
}
else Modifiers(SYNTHETIC)
Expand Down
4 changes: 2 additions & 2 deletions src/library/scala/collection/Iterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,8 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
object Iterator extends IterableFactory[Iterator] {

private[this] val _empty: Iterator[Nothing] = new AbstractIterator[Nothing] {
def hasNext = false
def next() = throw new NoSuchElementException("next on empty iterator")
override def hasNext: Boolean = false
override def next(): Nothing = throw new NoSuchElementException("next on empty iterator")
override def knownSize: Int = 0
override protected def sliceIterator(from: Int, until: Int): AbstractIterator[Nothing] = this
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/immutable/HashMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
currentValueCursor += 1
}

override def next() = Iterator.empty.next()
override def next(): (K, V) = Iterator.empty.next()
}
case hm: collection.mutable.HashMap[K, V] =>
val iter = hm.nodeIterator
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/immutable/HashSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ private[collection] final class HashSetBuilder[A] extends ReusableBuilder[A, Has
)
currentValueCursor += 1
}
override def next() = Iterator.empty.next()
override def next(): A = Iterator.empty.next()
}
case other =>
val it = other.iterator
Expand Down
36 changes: 24 additions & 12 deletions src/library/scala/concurrent/duration/Deadline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@

package scala.concurrent.duration

/**
* This class stores a deadline, as obtained via `Deadline.now` or the
* duration DSL:
import annotation.nowarn

/** A deadline, as a duration of time remaining, calculated from the present.
*
* Deadlines are obtained via `Deadline.now` or the duration DSL:
*
* {{{
* import scala.concurrent.duration._
* 3.seconds.fromNow
* }}}
* {{{
* import scala.concurrent.duration._
* 3.seconds.fromNow
* }}}
*
* Its main purpose is to manage repeated attempts to achieve something (like
* awaiting a condition) by offering the methods `hasTimeLeft` and `timeLeft`. All
* durations are measured according to `System.nanoTime`; this
* does not take into account changes to the system clock (such as leap
* seconds).
* The purpose of a deadline is to support managed repeated attempts,
* such as when awaiting a condition, by offering the methods `hasTimeLeft` and `timeLeft`.
*
* All durations are measured according to `System.nanoTime`;
* this does not take into account changes to the system clock, such as leap seconds.
*/
case class Deadline private (time: FiniteDuration) extends Ordered[Deadline] {
/**
* Return a deadline advanced (i.e., moved into the future) by the given duration.
*/
@nowarn("cat=deprecation")
def +(other: FiniteDuration): Deadline = copy(time = time + other)
/**
* Return a deadline moved backwards (i.e., towards the past) by the given duration.
*/
@nowarn("cat=deprecation")
def -(other: FiniteDuration): Deadline = copy(time = time - other)
/**
* Calculate time difference between this and the other deadline, where the result is directed (i.e., may be negative).
Expand Down Expand Up @@ -65,6 +69,10 @@ case class Deadline private (time: FiniteDuration) extends Ordered[Deadline] {
* The natural ordering for deadline is determined by the natural order of the underlying (finite) duration.
*/
def compare(other: Deadline): Int = time compare other.time

// expose public copy for backward compatibility under -Xsource:3
@deprecated("use now or FiniteDuration#fromNow", since="2.13.13")
def copy(time: FiniteDuration = this.time): Deadline = Deadline(time)
}

object Deadline {
Expand All @@ -73,6 +81,7 @@ object Deadline {
* advancing it to obtain a future deadline, or for sampling the current time exactly once and
* then comparing it to multiple deadlines (using subtraction).
*/
@nowarn("cat=deprecation")
def now: Deadline = Deadline(Duration(System.nanoTime, NANOSECONDS))

/**
Expand All @@ -82,4 +91,7 @@ object Deadline {
def compare(a: Deadline, b: Deadline): Int = a compare b
}

// expose public apply for backward compatibility under -Xsource:3
@deprecated("use now or FiniteDuration#fromNow", since="2.13.13")
def apply(time: FiniteDuration): Deadline = new Deadline(time)
}
6 changes: 3 additions & 3 deletions test/files/neg/t12798-migration.check
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ t12798-migration.scala:17: warning: Unicode escapes in raw interpolations are ig
t12798-migration.scala:18: warning: Unicode escapes in raw interpolations are ignored under -Xsource:3; use literal characters instead
def g = raw"""\u0043 is for Cat"""
^
t12798-migration.scala:50: warning: constructor modifiers are assumed by synthetic `copy` method
t12798-migration.scala:50: warning: access modifiers for `copy` method are copied from the case class constructor
case class `case mods propagate` private (s: String)
^
t12798-migration.scala:60: warning: under -Xsource:3, inferred Option[Int] instead of Some[Int] [quickfixable]
override def f = Some(27)
^
t12798-migration.scala:50: warning: constructor modifiers are assumed by synthetic `apply` method
t12798-migration.scala:50: warning: access modifiers for `apply` method are copied from the case class constructor
case class `case mods propagate` private (s: String)
^
t12798-migration.scala:52: warning: constructor modifiers are assumed by synthetic `apply` method
t12798-migration.scala:52: warning: access modifiers for `apply` method are copied from the case class constructor
case class `copyless case mods propagate` private (s: String) {
^
15 warnings
Expand Down
6 changes: 3 additions & 3 deletions test/files/neg/t12798.check
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=interpolated unicode such as C.g
def g = raw"""\u0043 is for Cat"""
^
t12798.scala:50: error: constructor modifiers are assumed by synthetic `copy` method
t12798.scala:50: error: access modifiers for `copy` method are copied from the case class constructor
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=case mods propagate
case class `case mods propagate` private (s: String)
Expand All @@ -70,9 +70,9 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Child.f
override def f = Some(27)
^
t12798.scala:52: error: constructor modifiers are assumed by synthetic `apply` method
t12798.scala:52: error: access modifiers for `apply` method are copied from the case class constructor
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=copyless case mods propagate
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=copyless case mods propagate.apply
case class `copyless case mods propagate` private (s: String) {
^
15 errors