Merge pull request #8368 from eed3si9n/wip/parser

[1.x] fix: Parse with -Xsource:3
This commit is contained in:
eugene yokota 2025-11-15 01:47:15 -05:00 committed by GitHub
commit dabfb24023
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 1 deletions

View File

@ -129,7 +129,7 @@ private[sbt] object SbtParser {
private[sbt] var scalacGlobalInitReporter: Option[ConsoleReporter] = None
private[sbt] final val (defaultGlobalForParser, globalReporter) = {
val options = "-cp" :: s"$defaultClasspath" :: "-Yrangepos" :: Nil
val options = "-cp" :: s"$defaultClasspath" :: "-Yrangepos" :: "-Xsource:3" :: Nil
val reportError = (msg: String) => System.err.println(msg)
val command = new CompilerCommand(options, reportError)
val settings = command.settings

View File

@ -0,0 +1,7 @@
ThisBuild / scalaVersion := "3.3.4"
def foo(): Unit = {
List("") match { case List(path@_*) => () }
List("") match { case List(path *) => () }
List("") match { case List(path*) => () }
}

View File

@ -0,0 +1,33 @@
/*
* sbt
* Copyright 2023, Scala center
* Copyright 2011 - 2022, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt
package internal
package parser
import java.io.File
import scala.io.Source
object Xsource3Spec extends AbstractSpec {
implicit val splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions
test("Parser should handle -Xsource:3 syntax") {
val rootPath = getClass.getResource("/xsource3").getPath
println(s"Reading files from: $rootPath")
val allFiles = new File(rootPath).listFiles.toList
allFiles foreach { path =>
println(s"$path")
val lines = Source.fromFile(path).getLines().toList
val (_, statements) = splitter(path, lines)
assert(statements.nonEmpty, s"""
|***should contains statements***
|$lines """.stripMargin)
}
}
}