Skip to content

Commit 7b751b4

Browse files
Backport "Improve message for nested package missing braces" to 3.7.4 (#24044)
Backports #23816 to the 3.7.4. PR submitted by the release tooling. [skip ci]
2 parents 52dcd29 + 963f55e commit 7b751b4

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import dotty.tools.vulpix.TestConfiguration.defaultOptions
4141
* using this, you should be running your JUnit tests **sequentially**, as the
4242
* test suite itself runs with a high level of concurrency.
4343
*/
44-
trait ParallelTesting extends RunnerOrchestration { self =>
45-
import ParallelTesting._
44+
trait ParallelTesting extends RunnerOrchestration:
45+
import ParallelTesting.*
4646

4747
/** If the running environment supports an interactive terminal, each `Test`
4848
* will be run with a progress bar and real time feedback
@@ -996,29 +996,33 @@ trait ParallelTesting extends RunnerOrchestration { self =>
996996
(errorMap, expectedErrors)
997997
end getErrorMapAndExpectedCount
998998

999-
// return unfulfilled expected errors and unexpected diagnostics
999+
// return unfulfilled expected errors and unexpected diagnostics.
1000+
// the errorMap of expected errors is drained and returned as unfulfilled.
1001+
// a diagnostic at EOF after NL is recorded at the preceding line,
1002+
// to obviate `anypos-error` in that case.
10001003
def getMissingExpectedErrors(errorMap: HashMap[String, Integer], reporterErrors: Iterator[Diagnostic]): (List[String], List[String]) =
10011004
val unexpected, unpositioned = ListBuffer.empty[String]
10021005
// For some reason, absolute paths leak from the compiler itself...
10031006
def relativize(path: String): String = path.split(JFile.separatorChar).dropWhile(_ != "tests").mkString(JFile.separator)
10041007
def seenAt(key: String): Boolean =
10051008
errorMap.get(key) match
1006-
case null => false
1007-
case 1 => errorMap.remove(key); true
1008-
case n => errorMap.put(key, n - 1); true
1009+
case null => false
1010+
case 1 => errorMap.remove(key); true
1011+
case n => errorMap.put(key, n - 1); true
10091012
def sawDiagnostic(d: Diagnostic): Unit =
1010-
d.pos.nonInlined match
1011-
case srcpos if srcpos.exists =>
1012-
val key = s"${relativize(srcpos.source.file.toString)}:${srcpos.line + 1}"
1013-
if !seenAt(key) then unexpected += key
1014-
case srcpos =>
1015-
if !seenAt("nopos") then unpositioned += relativize(srcpos.source.file.toString)
1013+
val srcpos = d.pos.nonInlined.adjustedAtEOF
1014+
val relatively = relativize(srcpos.source.file.toString)
1015+
if srcpos.exists then
1016+
val key = s"${relatively}:${srcpos.line + 1}"
1017+
if !seenAt(key) then unexpected += key
1018+
else
1019+
if !seenAt("nopos") then unpositioned += relatively
10161020

10171021
reporterErrors.foreach(sawDiagnostic)
10181022

1019-
errorMap.get("anypos") match
1020-
case n if n == unexpected.size => errorMap.remove("anypos") ; unexpected.clear()
1021-
case _ =>
1023+
if errorMap.get("anypos") == unexpected.size then
1024+
errorMap.remove("anypos")
1025+
unexpected.clear()
10221026

10231027
(errorMap.asScala.keys.toList, (unexpected ++ unpositioned).toList)
10241028
end getMissingExpectedErrors
@@ -1838,9 +1842,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
18381842
def isUserDebugging: Boolean =
18391843
val mxBean = ManagementFactory.getRuntimeMXBean
18401844
mxBean.getInputArguments.asScala.exists(_.contains("jdwp"))
1841-
}
18421845

1843-
object ParallelTesting {
1846+
object ParallelTesting:
18441847

18451848
def defaultOutputDir: String = "out"+JFile.separator
18461849

@@ -1855,4 +1858,14 @@ object ParallelTesting {
18551858
def isBestEffortTastyFile(f: JFile): Boolean =
18561859
f.getName.endsWith(".betasty")
18571860

1858-
}
1861+
extension (pos: SourcePosition)
1862+
private def adjustedAtEOF: SourcePosition =
1863+
if pos.span.isSynthetic
1864+
&& pos.span.isZeroExtent
1865+
&& pos.span.exists
1866+
&& pos.span.start == pos.source.length
1867+
&& pos.source(pos.span.start - 1) == '\n'
1868+
then
1869+
pos.withSpan(pos.span.shift(-1))
1870+
else
1871+
pos

tests/neg/parser-stability-11.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ case class x0 // error // error
33
}
44
package x0
55
class x0 // error
6-
// error
6+
// error

0 commit comments

Comments
 (0)