Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9ba237

Browse files
committed
Use -Xsource:3 and accommodate signature moves
1 parent 1a6c8c0 commit a9ba237

File tree

9 files changed

+49
-31
lines changed

9 files changed

+49
-31
lines changed

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ lazy val library = configureAsSubproject(project)
413413
name := "scala-library",
414414
description := "Scala Standard Library",
415415
Compile / scalacOptions ++= Seq("-sourcepath", (Compile / scalaSource).value.toString),
416-
Compile / scalacOptions ++= Seq("-Xlint", "-feature"),
416+
Compile / scalacOptions ++= Seq("-Xlint", "-feature", "-Xsource:3"),
417+
Compile / scalacOptions ++= Seq("-Wconf:cat=scala3-migration&msg=elidable&site=scala.Predef:s"),
418+
Compile / scalacOptions ++= Seq("-Wconf:cat=scala3-migration&msg=constructor modifiers&site=scala.concurrent.duration.Deadline:s"), // for bootstrap until restarr
417419
Compile / doc / scalacOptions ++= {
418420
val libraryAuxDir = (ThisBuild / baseDirectory).value / "src/library-aux"
419421
Seq(

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
33033303
def typedStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
33043304
val inBlock = exprOwner == context.owner
33053305
def includesTargetPos(tree: Tree) =
3306-
tree.pos.isRange && context.unit.exists && (tree.pos includes context.unit.targetPos)
3306+
tree.pos.isRange && context.unit.exists && tree.pos.includes(context.unit.targetPos)
33073307
val localTarget = stats exists includesTargetPos
33083308
def typedStat(stat: Tree): Tree = stat match {
33093309
case s if context.owner.isRefinementClass && !treeInfo.isDeclarationOrTypeDef(s) => OnlyDeclarationsError(s)
@@ -3418,8 +3418,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
34183418
// OPT: shouldAdd is usually true. Call it here, rather than in the outer loop
34193419
case Some(tree) if shouldAdd(sym) =>
34203420
// if the completer set the IS_ERROR flag, retract the stat (currently only used by applyUnapplyMethodCompleter)
3421-
if (!sym.initialize.hasFlag(IS_ERROR))
3422-
newStats += typedStat(tree) // might add even more synthetics to the scope
3421+
if (!sym.initialize.hasFlag(IS_ERROR)) {
3422+
val newStat = typedStat(tree)
3423+
if (currentRun.isScala3 && !sym.owner.isCaseClass)
3424+
tree match {
3425+
case DefDef(mods, nme.apply, _, _, _, _) if mods.hasFlag(PRIVATE) || mods.privateWithin != tpnme.EMPTY =>
3426+
runReporting.warning(tree.pos, "access modifiers for `apply` method are copied from the case class constructor", WarningCategory.Scala3Migration, sym)
3427+
case _ =>
3428+
}
3429+
newStats += newStat // might add even more synthetics to the scope
3430+
}
34233431
context.unit.synthetics -= sym
34243432
case _ => ()
34253433
}

src/compiler/scala/tools/nsc/typechecker/Unapplies.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ trait Unapplies extends ast.TreeDSL {
156156
val mods =
157157
if (applyShouldInheritAccess(inheritedMods))
158158
(caseMods | (inheritedMods.flags & PRIVATE)).copy(privateWithin = inheritedMods.privateWithin)
159-
.tap { mods =>
160-
if (currentRun.isScala3 && mods != caseMods)
161-
runReporting.warning(cdef.pos, "constructor modifiers are assumed by synthetic `apply` method", WarningCategory.Scala3Migration, cdef.symbol)
162-
}
163159
else
164160
caseMods
165161
factoryMeth(mods, nme.apply, cdef)
@@ -282,7 +278,7 @@ trait Unapplies extends ast.TreeDSL {
282278
Modifiers(SYNTHETIC | (inheritedMods.flags & AccessFlags), inheritedMods.privateWithin)
283279
.tap { mods =>
284280
if (currentRun.isScala3 && mods != Modifiers(SYNTHETIC))
285-
runReporting.warning(cdef.pos, "constructor modifiers are assumed by synthetic `copy` method", WarningCategory.Scala3Migration, cdef.symbol)
281+
runReporting.warning(cdef.pos, "access modifiers for `copy` method are copied from the case class constructor", WarningCategory.Scala3Migration, cdef.symbol)
286282
}
287283
}
288284
else Modifiers(SYNTHETIC)

src/library/scala/collection/Iterator.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,8 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
969969
object Iterator extends IterableFactory[Iterator] {
970970

971971
private[this] val _empty: Iterator[Nothing] = new AbstractIterator[Nothing] {
972-
def hasNext = false
973-
def next() = throw new NoSuchElementException("next on empty iterator")
972+
override def hasNext: Boolean = false
973+
override def next(): Nothing = throw new NoSuchElementException("next on empty iterator")
974974
override def knownSize: Int = 0
975975
override protected def sliceIterator(from: Int, until: Int): AbstractIterator[Nothing] = this
976976
}

src/library/scala/collection/immutable/HashMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ private[immutable] final class HashMapBuilder[K, V] extends ReusableBuilder[(K,
23812381
currentValueCursor += 1
23822382
}
23832383

2384-
override def next() = Iterator.empty.next()
2384+
override def next(): (K, V) = Iterator.empty.next()
23852385
}
23862386
case hm: collection.mutable.HashMap[K, V] =>
23872387
val iter = hm.nodeIterator

src/library/scala/collection/immutable/HashSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ private[collection] final class HashSetBuilder[A] extends ReusableBuilder[A, Has
20972097
)
20982098
currentValueCursor += 1
20992099
}
2100-
override def next() = Iterator.empty.next()
2100+
override def next(): A = Iterator.empty.next()
21012101
}
21022102
case other =>
21032103
val it = other.iterator

src/library/scala/concurrent/duration/Deadline.scala

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,33 @@
1212

1313
package scala.concurrent.duration
1414

15-
/**
16-
* This class stores a deadline, as obtained via `Deadline.now` or the
17-
* duration DSL:
15+
import annotation.nowarn
16+
17+
/** A deadline, as a duration of time remaining, calculated from the present.
18+
*
19+
* Deadlines are obtained via `Deadline.now` or the duration DSL:
1820
*
19-
* {{{
20-
* import scala.concurrent.duration._
21-
* 3.seconds.fromNow
22-
* }}}
21+
* {{{
22+
* import scala.concurrent.duration._
23+
* 3.seconds.fromNow
24+
* }}}
2325
*
24-
* Its main purpose is to manage repeated attempts to achieve something (like
25-
* awaiting a condition) by offering the methods `hasTimeLeft` and `timeLeft`. All
26-
* durations are measured according to `System.nanoTime`; this
27-
* does not take into account changes to the system clock (such as leap
28-
* seconds).
26+
* The purpose of a deadline is to support managed repeated attempts,
27+
* such as when awaiting a condition, by offering the methods `hasTimeLeft` and `timeLeft`.
28+
*
29+
* All durations are measured according to `System.nanoTime`;
30+
* this does not take into account changes to the system clock, such as leap seconds.
2931
*/
3032
case class Deadline private (time: FiniteDuration) extends Ordered[Deadline] {
3133
/**
3234
* Return a deadline advanced (i.e., moved into the future) by the given duration.
3335
*/
36+
@nowarn("cat=deprecation")
3437
def +(other: FiniteDuration): Deadline = copy(time = time + other)
3538
/**
3639
* Return a deadline moved backwards (i.e., towards the past) by the given duration.
3740
*/
41+
@nowarn("cat=deprecation")
3842
def -(other: FiniteDuration): Deadline = copy(time = time - other)
3943
/**
4044
* Calculate time difference between this and the other deadline, where the result is directed (i.e., may be negative).
@@ -65,6 +69,10 @@ case class Deadline private (time: FiniteDuration) extends Ordered[Deadline] {
6569
* The natural ordering for deadline is determined by the natural order of the underlying (finite) duration.
6670
*/
6771
def compare(other: Deadline): Int = time compare other.time
72+
73+
// expose public copy for backward compatibility under -Xsource:3
74+
@deprecated("use now or FiniteDuration#fromNow", since="2.13.13")
75+
def copy(time: FiniteDuration = this.time): Deadline = Deadline(time)
6876
}
6977

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

7887
/**
@@ -82,4 +91,7 @@ object Deadline {
8291
def compare(a: Deadline, b: Deadline): Int = a compare b
8392
}
8493

94+
// expose public apply for backward compatibility under -Xsource:3
95+
@deprecated("use now or FiniteDuration#fromNow", since="2.13.13")
96+
def apply(time: FiniteDuration): Deadline = new Deadline(time)
8597
}

test/files/neg/t12798-migration.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ t12798-migration.scala:17: warning: Unicode escapes in raw interpolations are ig
3838
t12798-migration.scala:18: warning: Unicode escapes in raw interpolations are ignored under -Xsource:3; use literal characters instead
3939
def g = raw"""\u0043 is for Cat"""
4040
^
41-
t12798-migration.scala:50: warning: constructor modifiers are assumed by synthetic `copy` method
41+
t12798-migration.scala:50: warning: access modifiers for `copy` method are copied from the case class constructor
4242
case class `case mods propagate` private (s: String)
4343
^
4444
t12798-migration.scala:60: warning: under -Xsource:3, inferred Option[Int] instead of Some[Int] [quickfixable]
4545
override def f = Some(27)
4646
^
47-
t12798-migration.scala:50: warning: constructor modifiers are assumed by synthetic `apply` method
47+
t12798-migration.scala:50: warning: access modifiers for `apply` method are copied from the case class constructor
4848
case class `case mods propagate` private (s: String)
4949
^
50-
t12798-migration.scala:52: warning: constructor modifiers are assumed by synthetic `apply` method
50+
t12798-migration.scala:52: warning: access modifiers for `apply` method are copied from the case class constructor
5151
case class `copyless case mods propagate` private (s: String) {
5252
^
5353
15 warnings

test/files/neg/t12798.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
6060
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=interpolated unicode such as C.g
6161
def g = raw"""\u0043 is for Cat"""
6262
^
63-
t12798.scala:50: error: constructor modifiers are assumed by synthetic `copy` method
63+
t12798.scala:50: error: access modifiers for `copy` method are copied from the case class constructor
6464
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
6565
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=case mods propagate
6666
case class `case mods propagate` private (s: String)
@@ -70,9 +70,9 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
7070
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Child.f
7171
override def f = Some(27)
7272
^
73-
t12798.scala:52: error: constructor modifiers are assumed by synthetic `apply` method
73+
t12798.scala:52: error: access modifiers for `apply` method are copied from the case class constructor
7474
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
75-
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=copyless case mods propagate
75+
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=copyless case mods propagate.apply
7676
case class `copyless case mods propagate` private (s: String) {
7777
^
7878
15 errors

0 commit comments

Comments
 (0)