Skip to content

Commit

Permalink
Merge pull request #10291 from som-snytt/issue/12714-kotlin-deprecation
Browse files Browse the repository at this point in the history
Honor more deprecations under separate compilation
  • Loading branch information
lrytz committed Feb 21, 2023
2 parents 7197b0d + 4d5849a commit eae0711
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {

case tpnme.DeprecatedATTR =>
in.skip(attrLen)
sym.addAnnotation(JavaDeprecatedAttr)
if (sym == clazz)
staticModule.addAnnotation(JavaDeprecatedAttr)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
override def enterSyntheticSym(tree: Tree): Symbol = tree.symbol
}

protected override def newBodyDuplicator(context: Context): SpecializeBodyDuplicator =
override protected def newBodyDuplicator(context: Context): SpecializeBodyDuplicator =
new SpecializeBodyDuplicator(context)

override def newNamer(context: Context): Namer =
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class Duplicators extends Analyzer {
private var envSubstitution: SubstTypeMap = _

private class SubstSkolemsTypeMap(from: List[Symbol], to: List[Type]) extends SubstTypeMap(from, to) {
protected override def matches(sym1: Symbol, sym2: Symbol) =
override protected def matches(sym1: Symbol, sym2: Symbol) =
if (sym2.isTypeSkolem) sym2.deSkolemize eq sym1
else sym1 eq sym2
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/ArrayDeque.scala
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class ArrayDeque[A] protected (

override def isEmpty = start == end

protected override def klone(): ArrayDeque[A] = new ArrayDeque(array.clone(), start = start, end = end)
override protected def klone(): ArrayDeque[A] = new ArrayDeque(array.clone(), start = start, end = end)

override def iterableFactory: SeqFactory[ArrayDeque] = ArrayDeque

Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Queue[A] protected (array: Array[AnyRef], start: Int, end: Int)
*/
@`inline` final def front: A = head

protected override def klone(): Queue[A] = {
override protected def klone(): Queue[A] = {
val bf = newSpecificBuilder
bf ++= this
bf.result()
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Stack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Stack[A] protected (array: Array[AnyRef], start: Int, end: Int)
*/
@`inline` final def top: A = head

protected override def klone(): Stack[A] = {
override protected def klone(): Stack[A] = {
val bf = newSpecificBuilder
bf ++= this
bf.result()
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/UnrolledBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,5 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
// Todo -- revisit whether inheritance is the best way to achieve this functionality
private[collection] class DoublingUnrolledBuffer[T](implicit t: ClassTag[T]) extends UnrolledBuffer[T]()(t) {
override def calcNextLength(sz: Int) = if (sz < 10000) sz * 2 else sz
protected override def newUnrolled = new UnrolledBuffer.Unrolled[T](0, new Array[T](4), null, this)
override protected def newUnrolled = new UnrolledBuffer.Unrolled[T](0, new Array[T](4), null, this)
}
2 changes: 1 addition & 1 deletion src/partest/scala/tools/partest/nest/DirectCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class DirectCompiler(val runner: Runner) {
if (command.files.nonEmpty) reportError(command.files.mkString("flags file may only contain compiler options, found: ", space, ""))
}

suiteRunner.verbose(s"% compiling ${ sources.map(_.testIdent).mkString(space) }${ if (suiteRunner.debug) " -d " + outDir else ""}")
suiteRunner.verbose(sources.map(_.testIdent).mkString("% compiling ", space, if (suiteRunner.debug) s" -d $outDir" else ""))

def execCompile() =
if (command.shouldStopWithInfo) {
Expand Down
47 changes: 22 additions & 25 deletions src/partest/scala/tools/partest/nest/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,15 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
* 2. Runs script function, providing log file and output directory as arguments.
* 2b. or, just run the script without context and return a new context
*/
def runInContext(body: => TestState): TestState = {
body
}
def runInContext(body: => TestState): TestState = body

/** Grouped files in group order, and lex order within each group. */
def groupedFiles(sources: List[File]): List[List[File]] = (
def groupedFiles(sources: List[File]): List[List[File]] =
if (sources.sizeIs > 1) {
val grouped = sources groupBy (_.group)
grouped.keys.toList.sorted map (k => grouped(k) sortBy (_.getName))
val grouped = sources.groupBy(_.group)
grouped.keys.toList.sorted.map(grouped(_).sortBy(_.getName))
}
else List(sources)
)

/** Source files for the given test file. */
def sources(file: File): List[File] = if (file.isDirectory) file.listFiles.toList.filter(_.isJavaOrScala) else List(file)
Expand Down Expand Up @@ -489,31 +486,31 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
files.flatMap(argsFor)
}

abstract class CompileRound {
def fs: List[File]
def result: TestState
sealed abstract class CompileRound {
def files: List[File]
def description: String
protected def computeResult: TestState

final lazy val result: TestState = { pushTranscript(description); computeResult }

def fsString = fs map (_.toString stripPrefix parentFile.toString + "/") mkString " "
def isOk = result.isOk
def mkScalacString(): String = s"""scalac $fsString"""
override def toString = description + ( if (result.isOk) "" else "\n" + result.status )
final protected def fsString = files.map(_.toString.stripPrefix(s"$parentFile/")).mkString(" ")
final override def toString = description + ( if (result.isOk) "" else "\n" + result.status )
}
case class OnlyJava(fs: List[File]) extends CompileRound {
final case class OnlyJava(files: List[File]) extends CompileRound {
def description = s"""javac $fsString"""
lazy val result = { pushTranscript(description) ; javac(fs) }
override protected def computeResult = javac(files)
}
case class OnlyScala(fs: List[File]) extends CompileRound {
def description = mkScalacString()
lazy val result = { pushTranscript(description) ; attemptCompile(fs) }
final case class OnlyScala(files: List[File]) extends CompileRound {
def description = s"""scalac $fsString"""
override protected def computeResult = attemptCompile(files)
}
case class ScalaAndJava(fs: List[File]) extends CompileRound {
def description = mkScalacString()
lazy val result = { pushTranscript(description) ; attemptCompile(fs) }
final case class ScalaAndJava(files: List[File]) extends CompileRound {
def description = s"""scalac $fsString"""
override protected def computeResult = attemptCompile(files)
}
case class SkipRound(fs: List[File], state: TestState) extends CompileRound {
final case class SkipRound(files: List[File], state: TestState) extends CompileRound {
def description: String = state.status
lazy val result = { pushTranscript(description); state }
override protected def computeResult = state
}

def compilationRounds(file: File): List[CompileRound] = {
Expand Down Expand Up @@ -541,7 +538,7 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
}

def mixedCompileGroup(allFiles: List[File]): List[CompileRound] = {
val (scalaFiles, javaFiles) = allFiles partition (_.isScala)
val (scalaFiles, javaFiles) = allFiles.partition(_.isScala)
val round1 = if (scalaFiles.isEmpty) None else Some(ScalaAndJava(allFiles))
val round2 = if (javaFiles.isEmpty) None else Some(OnlyJava(javaFiles))

Expand Down
12 changes: 9 additions & 3 deletions src/partest/scala/tools/partest/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ package object partest {

/** Sources have a numerical group, specified by name_7 and so on. */
private val GroupPattern = """.*_(\d+)""".r
private object IntOf {
def unapply(ds: String): Some[Int] = Some {
try ds.toInt
catch { case _: NumberFormatException => -1 }
}
}

implicit class `special string ops`(private val s: String) extends AnyVal {
def linesIfNonEmpty: Iterator[String] = if (!s.isEmpty) s.linesIterator else Iterator.empty
Expand Down Expand Up @@ -85,11 +91,11 @@ package object partest {
def hasExtension(ext: String) = sf hasExtension ext
def changeExtension(ext: String): File = (sf changeExtension ext).jfile

/** The group number for this source file, or -1 for no group. */
/** The group number for this source file, or -1 for no group or out of range. */
def group: Int =
sf.stripExtension match {
case GroupPattern(g) if g.toInt >= 0 => g.toInt
case _ => -1
case GroupPattern(IntOf(g)) => g
case _ => -1
}

// Files.readString on jdk 11
Expand Down
30 changes: 28 additions & 2 deletions test/files/jvm/deprecation.check
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
Note: deprecation/Use_2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Test_1.scala:7: warning: variable i in class Defs is deprecated
val u = d.i + 1
^
Test_1.scala:8: warning: variable i in class Defs is deprecated
d.i = 2
^
Test_1.scala:9: warning: method bar in class Defs is deprecated
val v = d.bar()
^
Test_1.scala:10: warning: class Inner in class Defs is deprecated
val i = new d.Inner
^
deprecation/Use_2.java:7: warning: [deprecation] Test.Inner in Test has been deprecated
Test.Inner a = u.new Inner();
^
deprecation/Use_2.java:7: warning: [deprecation] Test.Inner in Test has been deprecated
Test.Inner a = u.new Inner();
^
deprecation/Use_2.java:8: warning: [deprecation] f() in Test.Inner has been deprecated
int i = a.f();
^
deprecation/Use_2.java:9: warning: [deprecation] g() in Test.Inner has been deprecated
int j = a.g();
^
deprecation/Use_2.java:10: warning: [deprecation] g_$eq(int) in Test.Inner has been deprecated
a.g_$eq(5);
^
5 warnings
3 changes: 3 additions & 0 deletions test/files/jvm/deprecation/Test_1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

// scalac: -Xlint:deprecation

class Test {
def test: Unit = {
val d = new Defs
Expand Down
5 changes: 4 additions & 1 deletion test/files/jvm/deprecation/Use_2.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

// javac: -Xlint:deprecation

class Use_2 {
public int test() {
Test u = new Test();
Expand All @@ -7,4 +10,4 @@ public int test() {
a.g_$eq(5);
return i + j;
}
}
}
5 changes: 4 additions & 1 deletion test/files/neg/t10752.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Test_2.scala:2: warning: class DeprecatedClass in package p1 is deprecated
object Test extends p1.DeprecatedClass {
^
Test_2.scala:3: warning: class DeprecatedClass in package p1 is deprecated
def useC = p1.DeprecatedClass.foo
^
Test_2.scala:4: warning: method foo in class DeprecatedMethod is deprecated
def useM = p1.DeprecatedMethod.foo
^
error: No warnings can be incurred under -Werror.
2 warnings
3 warnings
1 error
2 changes: 1 addition & 1 deletion test/files/neg/t10752/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// scalac: -Xlint:deprecation -Werror
object Test {
object Test extends p1.DeprecatedClass {
def useC = p1.DeprecatedClass.foo
def useM = p1.DeprecatedMethod.foo
}
5 changes: 4 additions & 1 deletion test/files/neg/t9617.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Test.scala:4: warning: class DeprecatedClass in package p1 is deprecated
object Test extends p1.DeprecatedClass {
^
Test.scala:5: warning: class DeprecatedClass in package p1 is deprecated
def useC = p1.DeprecatedClass.foo
^
Test.scala:6: warning: method foo in class DeprecatedMethod is deprecated
def useM = p1.DeprecatedMethod.foo
^
error: No warnings can be incurred under -Werror.
2 warnings
3 warnings
1 error
4 changes: 2 additions & 2 deletions test/files/neg/t9617/Test.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// scalac: -Xfatal-warnings -deprecation
// scalac: -Werror -Xlint:deprecation

// Joint-compilation copy of test/files/neg/t10752/Test_2.scala
object Test {
object Test extends p1.DeprecatedClass {
def useC = p1.DeprecatedClass.foo
def useM = p1.DeprecatedMethod.foo
}

0 comments on commit eae0711

Please sign in to comment.