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

Improve handling of language flags by Vulpix #10216

Merged
merged 2 commits into from
Feb 9, 2021
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
18 changes: 6 additions & 12 deletions compiler/test/dotty/tools/vulpix/TestFlags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@ final case class TestFlags(
private val languageFeatureFlag = "-language:"
private def withoutLanguageFeaturesOptions = options.filterNot(_.startsWith(languageFeatureFlag))

// TODO simplify to add `-language:feature` to `options` once
// https://github.com/lampepfl/dotty-feature-requests/issues/107 is implemented
def andLanguageFeature(feature: String) = {
val (languageFeatures, rest) = options.partition(_.startsWith(languageFeatureFlag))
val existingFeatures = if (languageFeatures.isEmpty) languageFeatures.mkString(",") + "," else ""
copy(options = rest ++ Array(languageFeatureFlag + existingFeatures + feature))
}
def andLanguageFeature(feature: String) =
copy(options = options ++ Array(s"$languageFeatureFlag$feature"))

def withoutLanguageFeature(feature: String) = {
def withoutLanguageFeature(feature: String) =
val (languageFeatures, rest) = options.partition(_.startsWith(languageFeatureFlag))
val filteredFeatures = languageFeatures.filter(_ == feature)
val existingFeatures = languageFeatures.flatMap(_.stripPrefix(languageFeatureFlag).split(","))
val filteredFeatures = existingFeatures.filterNot(_ == feature)
val newOptions =
if (filteredFeatures.isEmpty) rest
if filteredFeatures.isEmpty then rest
else rest ++ Array(languageFeatureFlag + filteredFeatures.mkString(","))

copy(options = newOptions)
}

/** Subset of the flags that should be passed to javac. */
def javacFlags: Array[String] = {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/i5498-postfixOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ def test() = {
1 second // error: usage of postfix operator

Seq(1, 2).filter(List(1,2) contains) // error: usage of postfix operator
}
}
4 changes: 2 additions & 2 deletions tests/pos-custom-args/i5498-postfixOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import scala.language.postfixOps
def test() = {
1 second

Seq(1, 2) filter (List(1,2) contains)
}
Seq(1, 2) filter (List(1,2) contains) toList
}