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

Backport "Move tests/init from neg to warn" to LTS #20809

Merged
merged 1 commit into from
Jun 26, 2024
Merged
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
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class CompilationTests {
implicit val testGroup: TestGroup = TestGroup("checkInit")
val options = defaultOptions.and("-Ysafe-init", "-Xfatal-warnings")
compileFilesInDir("tests/init/neg", options).checkExpectedErrors()
compileFilesInDir("tests/init/warn", defaultOptions.and("-Ysafe-init")).checkWarnings()
compileFilesInDir("tests/init/pos", options).checkCompile()
compileFilesInDir("tests/init/crash", options.without("-Xfatal-warnings")).checkCompile()

Expand Down
11 changes: 7 additions & 4 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
end maybeFailureMessage

def getWarnMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) =
val comment = raw"//( *)warn".r
val comment = raw"//( *)(nopos-)?warn".r
val map = new HashMap[String, Integer]()
var count = 0
def bump(key: String): Unit =
Expand All @@ -766,8 +766,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
files.filter(isSourceFile).foreach { file =>
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
comment.findAllMatchIn(line).foreach { _ =>
bump(s"${file.getPath}:${lineNbr+1}")
comment.findAllMatchIn(line).foreach { m =>
m.group(2) match
case "nopos-" =>
bump("nopos")
case _ => bump(s"${file.getPath}:${lineNbr+1}")
}
}
}.get
Expand All @@ -788,7 +791,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
val key = s"${relativize(srcpos.source.file.toString())}:${srcpos.line + 1}"
if !seenAt(key) then unexpected += key
else
unpositioned += relativize(srcpos.source.file.toString())
if(!seenAt("nopos")) unpositioned += relativize(srcpos.source.file.toString())

reporterWarnings.foreach(sawDiagnostic)

Expand Down
6 changes: 0 additions & 6 deletions tests/init/neg/early-promote2.scala

This file was deleted.

19 changes: 0 additions & 19 deletions tests/init/neg/i12544.scala

This file was deleted.

20 changes: 0 additions & 20 deletions tests/init/neg/inner9.scala

This file was deleted.

4 changes: 0 additions & 4 deletions tests/init/neg/simple1.scala

This file was deleted.

3 changes: 0 additions & 3 deletions tests/init/neg/soundness4.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ abstract class AbstractFile {
}

class RemoteFile(url: String) extends AbstractFile {
val localFile: String = s"${url.##}.tmp" // error: usage of `localFile` before it's initialized
val localFile: String = s"${url.##}.tmp" // warn: usage of `localFile` before it's initialized
def name: String = localFile
}
2 changes: 1 addition & 1 deletion tests/init/neg/alias.scala → tests/init/warn/alias.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Foo {
val self = this
val x = self.n
val n = 10 // error
val n = 10 // warn
}
6 changes: 3 additions & 3 deletions tests/init/neg/apply.scala → tests/init/warn/apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object A:

class B:
val a = A(this)
val a2 = A.foo(this) // error
val a2 = A.foo(this) // warn
val a3 = A.bar(this)

// test receiver is ThisRef
Expand All @@ -20,7 +20,7 @@ object O:

class B:
val a = A(this)
val a2 = A.foo(this) // error
val a2 = A.foo(this) // warn
val a3 = A.bar(this)

val b = new B
Expand All @@ -38,7 +38,7 @@ class M(n: N):

class B:
val a = A(this)
val a2 = A.foo(this) // error
val a2 = A.foo(this) // warn
val a3 = A.bar(this)
end M

Expand Down
4 changes: 2 additions & 2 deletions tests/init/neg/apply2.scala → tests/init/warn/apply2.scala
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
object O:
class O:
case class A(b: B):
println(n)

class B:
val a = A(this) // error
val a = A(this) // warn

val b = new B
val n = 10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
final class MyAsInstanceOfClass(o: MyAsInstanceOfClass) {
val other: MyAsInstanceOfClass = {
if (o.asInstanceOf[MyAsInstanceOfClass].oRef ne null) o
else new MyAsInstanceOfClass(this) // error
else new MyAsInstanceOfClass(this) // warn
}
val oRef = o
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ object Foo {
}

class A {
val foo = implicitly[Foo] // error
val foo = implicitly[Foo] // warn
assert(foo eq foo.next)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Outer {
}

val l: List[A] = List(new A(5), new A(10))
l.foreach(a => a.addX(this)) // error
l.foreach(a => a.addX(this)) // warn
val p = 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object A:

class B {
var a = new Array[B](2)
A.foo(this, a) // error
A.foo(this, a) // warn
println(a(0).i)
val i = 99
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
case class A(b: B) {
val x1 = b.x
val x = B(this) // error
val x = B(this) // warn
val y = x.a
}

case class B(a: A) {
val x1 = a.x
val x = A(this) // error
val x = A(this) // warn
val h = x.b
}
4 changes: 2 additions & 2 deletions tests/init/neg/cycle.scala → tests/init/warn/cycle.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class A(x: B) {
println(x.b)
val a = new B(this) // error
val a = new B(this) // warn
val d = a.b
}

class B(x: A) {
println(x.a)
val b = new A(this) // error
val b = new A(this) // warn
val d = b.a
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class A {
class B extends A {
def updateThenCompare(c: Int): Boolean = {
x = c
compare() // error
compare() // warn
}
val result = updateThenCompare(5)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class A { // checking A
def c = new C
}
val b = new B()
println(b) // error: the checker simply issue warnings for objects that contain inner classes
println(b) // warn: the checker simply issue warnings for objects that contain inner classes
val af = 42
}

Expand Down
6 changes: 6 additions & 0 deletions tests/init/warn/early-promote2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class M {
println(this) // warn
foo()
private val a = 5 // warn
def foo() = a
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ abstract class A {
}

class M extends A {
def bar() = promote(this) // error
def bar() = promote(this) // warn
def promote(m: M) = m.foo()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class Outer {

class Dummy {
val m: Int = n + 4
val n: Int = 10 // error
val n: Int = 10 // warn
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Outer {

class Container {
val o = new Outer
val m = new o.M(this) // error
val m = new o.M(this) // warn
val s = "hello"
}

class Dummy {
val m: Int = n + 4
val n: Int = 10 // error
val n: Int = 10 // warn
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Foo {
val a = Foo.bar(this) // error
val a = Foo.bar(this) // warn
val b = "hello"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ abstract class Parent {
}
class Child extends Parent {
val a = f()
val b = "hello" // error
val b = "hello" // warn
def message: String = b
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
trait TA {
val x = "world" // error
val x = "world" // warn
}

trait TB {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class Trees {
class ValDef { counter += 1 }
class EmptyValDef extends ValDef
val theEmptyValDef = new EmptyValDef
private var counter = 0 // error
private var counter = 0 // warn
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ trait U {
val f2: Int
}

object Test0 extends U {
class Test0 extends U {
final val f1 = 1
final val f2 = 2
final val f3 = f1 + f2
val f4: 3 = f3
}

object Test1 extends U {
class Test1 extends U {
final val f1 = 1
final val f3 = f1 + f2
final val f2 = 2
Expand All @@ -28,16 +28,16 @@ object Test1 extends U {

}

object Test extends T {
override final val f1 = /*super.f1*/ 1 + f2 // error
override final val f2 = 2 // error
override final val f3 = {println(3); 3} // error
override val f4 = f3 + 1 // error
class Test extends T {
override final val f1 = /*super.f1*/ 1 + f2 // warn
override final val f2 = 2 // warn
override final val f3 = {println(3); 3} // warn
override val f4 = f3 + 1 // warn

def g: 3 = { println("g"); 3 }
final val x = g + 1
def main(args: Array[String]): Unit = {
Test0
Test1
new Test0
new Test1
}
}
2 changes: 1 addition & 1 deletion tests/init/neg/flow2.scala → tests/init/warn/flow2.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Foo {
val len = list.size
val list = List(4, 6) // error
val list = List(4, 6) // warn

lazy val len2 = list2.size // ok
val list2 = List(4, 6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class Foo {
val f: Int => Foo = (x: Int) => if x > 0 then f(x) else this
f(10).n

val n = 10 // error
val n = 10 // warn
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class Foo {
val fun2: Int => Int = n => 1 + n + list.size
fun2(5)

List(5, 9).map(n => 2 + n + list.size) // error
List(5, 9).map(n => 2 + n + list.size) // warn

final val list = List(1, 2, 3) // error
final val list = List(1, 2, 3) // warn

List(5, 9).map(n => 3 + n + list.size)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Base { self =>
(0 to 10).foreach { i => // error
(0 to 10).foreach { i => // warn
println(a)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
final class Capture {
private[this] var m: Boolean = false
private var m: Boolean = false

(0 to 10).foreach { i => // error
(0 to 10).foreach { i => // warn
f()
}

Expand All @@ -14,7 +14,7 @@ final class Capture {
}

final class Capture2 {
private[this] var m: Boolean = false
private var m: Boolean = false

(0 to 10).foreach { i =>
f()
Expand Down
Loading