Skip to content

Commit 19b7386

Browse files
committed
Warn nopos & tests/init refactor for warn tests
1 parent 69cc6b1 commit 19b7386

File tree

153 files changed

+199
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+199
-195
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class CompilationTests {
225225
implicit val testGroup: TestGroup = TestGroup("checkInit")
226226
val options = defaultOptions.and("-Ysafe-init", "-Xfatal-warnings")
227227
compileFilesInDir("tests/init/neg", options).checkExpectedErrors()
228+
compileFilesInDir("tests/init/warn", defaultOptions.and("-Ysafe-init")).checkWarnings()
228229
compileFilesInDir("tests/init/pos", options).checkCompile()
229230
compileFilesInDir("tests/init/crash", options.without("-Xfatal-warnings")).checkCompile()
230231
// The regression test for i12128 has some atypical classpath requirements.

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
776776
end maybeFailureMessage
777777

778778
def getWarnMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) =
779-
val comment = raw"//( *)warn".r
779+
val comment = raw"//( *)(nopos-)?warn".r
780780
val map = new HashMap[String, Integer]()
781781
var count = 0
782782
def bump(key: String): Unit =
@@ -787,8 +787,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
787787
files.filter(isSourceFile).foreach { file =>
788788
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
789789
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
790-
comment.findAllMatchIn(line).foreach { _ =>
791-
bump(s"${file.getPath}:${lineNbr+1}")
790+
comment.findAllMatchIn(line).foreach { m =>
791+
m.group(2) match
792+
case "nopos-" =>
793+
bump("nopos")
794+
case _ => bump(s"${file.getPath}:${lineNbr+1}")
792795
}
793796
}
794797
}.get
@@ -809,7 +812,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
809812
val key = s"${relativize(srcpos.source.file.toString())}:${srcpos.line + 1}"
810813
if !seenAt(key) then unexpected += key
811814
else
812-
unpositioned += relativize(srcpos.source.file.toString())
815+
if(!seenAt("nopos")) unpositioned += relativize(srcpos.source.file.toString())
813816

814817
reporterWarnings.foreach(sawDiagnostic)
815818

tests/init/neg/early-promote2.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/init/neg/simple1.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/init/neg/soundness4.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/init/neg/AbstractFile.scala renamed to tests/init/warn/AbstractFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ abstract class AbstractFile {
44
}
55

66
class RemoteFile(url: String) extends AbstractFile {
7-
val localFile: String = s"${url.##}.tmp" // error: usage of `localFile` before it's initialized
7+
val localFile: String = s"${url.##}.tmp" // warn: usage of `localFile` before it's initialized
88
def name: String = localFile
99
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Foo {
22
val self = this
33
val x = self.n
4-
val n = 10 // error
4+
val n = 10 // warn
55
}

tests/init/neg/apply.scala renamed to tests/init/warn/apply.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object A:
66

77
class B:
88
val a = A(this)
9-
val a2 = A.foo(this) // error
9+
val a2 = A.foo(this) // warn
1010
val a3 = A.bar(this)
1111

1212
// test receiver is ThisRef
@@ -20,7 +20,7 @@ object O:
2020

2121
class B:
2222
val a = A(this)
23-
val a2 = A.foo(this) // error
23+
val a2 = A.foo(this) // warn
2424
val a3 = A.bar(this)
2525

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

3939
class B:
4040
val a = A(this)
41-
val a2 = A.foo(this) // error
41+
val a2 = A.foo(this) // warn
4242
val a3 = A.bar(this)
4343
end M
4444

tests/init/neg/apply2.scala renamed to tests/init/warn/apply2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class O:
33
println(n)
44

55
class B:
6-
val a = A(this) // error
6+
val a = A(this) // warn
77

88
val b = new B
99
val n = 10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
final class MyAsInstanceOfClass(o: MyAsInstanceOfClass) {
22
val other: MyAsInstanceOfClass = {
33
if (o.asInstanceOf[MyAsInstanceOfClass].oRef ne null) o
4-
else new MyAsInstanceOfClass(this) // error
4+
else new MyAsInstanceOfClass(this) // warn
55
}
66
val oRef = o
77
}

0 commit comments

Comments
 (0)