Skip to content

Commit 73fb460

Browse files
committed
Merge pull request scala#3888 from som-snytt/issue/8736
SI-8736 Restore -language to former glory
2 parents afa96e3 + 5a30c40 commit 73fb460

File tree

10 files changed

+54
-9
lines changed

10 files changed

+54
-9
lines changed

src/compiler/scala/tools/nsc/settings/AbsScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait AbsScalaSettings {
2929
def ChoiceSetting(name: String, helpArg: String, descr: String, choices: List[String], default: String): ChoiceSetting
3030
def IntSetting(name: String, descr: String, default: Int, range: Option[(Int, Int)], parser: String => Option[Int]): IntSetting
3131
def MultiStringSetting(name: String, helpArg: String, descr: String): MultiStringSetting
32-
def MultiChoiceSetting(name: String, helpArg: String, descr: String, choices: List[String], default: () => Unit)(helper: MultiChoiceSetting => String): MultiChoiceSetting
32+
def MultiChoiceSetting(name: String, helpArg: String, descr: String, choices: List[String], default: Option[() => Unit])(helper: MultiChoiceSetting => String): MultiChoiceSetting
3333
def OutputSetting(outputDirs: OutputDirs, default: String): OutputSetting
3434
def PathSetting(name: String, descr: String, default: String): PathSetting
3535
def PhasesSetting(name: String, descr: String, default: String): PhasesSetting

src/compiler/scala/tools/nsc/settings/MutableSettings.scala

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class MutableSettings(val errorFn: String => Unit)
211211
add(new ChoiceSetting(name, helpArg, descr, choices, default))
212212
def IntSetting(name: String, descr: String, default: Int, range: Option[(Int, Int)], parser: String => Option[Int]) = add(new IntSetting(name, descr, default, range, parser))
213213
def MultiStringSetting(name: String, arg: String, descr: String) = add(new MultiStringSetting(name, arg, descr))
214-
def MultiChoiceSetting(name: String, helpArg: String, descr: String, choices: List[String], default: () => Unit = () => ())(
214+
def MultiChoiceSetting(name: String, helpArg: String, descr: String, choices: List[String], default: Option[() => Unit] = None)(
215215
helper: MultiChoiceSetting => String = _ => choices.mkString(f"$descr:%n", f"%n ", f"%n")
216216
) =
217217
add(new MultiChoiceSetting(name, helpArg, descr, choices, default, helper))
@@ -563,19 +563,23 @@ class MutableSettings(val errorFn: String => Unit)
563563
arg: String,
564564
descr: String,
565565
override val choices: List[String],
566-
val default: () => Unit,
566+
val default: Option[() => Unit],
567567
helper: MultiChoiceSetting => String
568568
) extends MultiStringSetting(name, s"_,$arg,-$arg", s"$descr: `_' for all, `$name:help' to list") {
569569

570570
private def badChoice(s: String, n: String) = errorFn(s"'$s' is not a valid choice for '$name'")
571571
private def choosing = choices.nonEmpty
572572
private def isChoice(s: String) = (s == "_") || (choices contains (s stripPrefix "-"))
573-
private var sawHelp = false
573+
574+
private var sawHelp = false
575+
private var sawAll = false
576+
private val adderAll = () => sawAll = true
577+
private val noargs = () => errorFn(s"'$name' requires an option. See '$name:help'.")
574578

575579
override protected def tts(args: List[String], halting: Boolean) = {
576580
val added = collection.mutable.ListBuffer.empty[String]
577581
def tryArg(arg: String) = arg match {
578-
case "_" if choosing => default()
582+
case "_" if choosing => addAll()
579583
case "help" if choosing => sawHelp = true
580584
case s if !choosing || isChoice(s) => added += s
581585
case s => badChoice(s, name)
@@ -587,13 +591,19 @@ class MutableSettings(val errorFn: String => Unit)
587591
case Nil => Nil
588592
}
589593
val rest = loop(args)
590-
if (rest.size == args.size) default() // if no arg consumed, trigger default action
591-
else value = added.toList // update all new settings at once
594+
if (rest.size == args.size)
595+
(default getOrElse noargs)() // if no arg consumed, trigger default action or error
596+
else
597+
value ++= added.toList // update all new settings at once
592598
Some(rest)
593599
}
594600

595601
def isHelping: Boolean = sawHelp
596-
def help: String = helper(this)
602+
def help: String = helper(this)
603+
def addAll(): Unit = (default getOrElse adderAll)()
604+
605+
// the semantics is: s is enabled, i.e., either s or (_ but not -s)
606+
override def contains(s: String) = isChoice(s) && (value contains s) || (sawAll && !(value contains s"-$s"))
597607
}
598608

599609
/** A setting that accumulates all strings supplied to it,

src/compiler/scala/tools/nsc/settings/Warnings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ trait Warnings {
116116
helpArg = "warning",
117117
descr = description,
118118
choices = choices,
119-
default = () => xlint.value = true
119+
default = Some(() => xlint.value = true)
120120
) { s =>
121121
def helpline(n: String) = lintWarnings.find(_.name == n).map(w => f" ${w.name}%-25s ${w.helpDescription}%n")
122122
choices flatMap (helpline(_)) mkString (f"$description:%n", "", f"%n")

test/files/neg/t8736-c.check

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
t8736-c.scala:4: warning: higher-kinded type should be enabled
2+
by making the implicit value scala.language.higherKinds visible.
3+
This can be achieved by adding the import clause 'import scala.language.higherKinds'
4+
or by setting the compiler option -language:higherKinds.
5+
See the Scala docs for value scala.language.higherKinds for a discussion
6+
why the feature should be explicitly enabled.
7+
def hk[M[_]] = ???
8+
^
9+
error: No warnings can be incurred under -Xfatal-warnings.
10+
one warning found
11+
one error found

test/files/neg/t8736-c.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-feature -language:-higherKinds,_ -Xfatal-warnings

test/files/neg/t8736-c.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// scalac: -feature -language:-higherKinds,_ -Xfatal-warnings
2+
// showing that wildcard doesn't supersede explicit disablement
3+
class X {
4+
def hk[M[_]] = ???
5+
6+
implicit def imp(x: X): Int = x.hashCode
7+
}

test/files/pos/t8736-b.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-feature -language:_ -Xfatal-warnings

test/files/pos/t8736-b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// scalac: -feature -language:_ -Xfatal-warnings
2+
// showing that all are set
3+
class X {
4+
def hk[M[_]] = ???
5+
6+
implicit def imp(x: X): Int = x.hashCode
7+
}

test/files/pos/t8736.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-feature -language:implicitConversions -language:higherKinds -language:-implicitConversions -Xfatal-warnings

test/files/pos/t8736.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// scalac: -feature -language:implicitConversions -language:higherKinds -language:-implicitConversions -Xfatal-warnings
2+
// showing that multiple settings are respected, and explicit enablement has precedence
3+
class X {
4+
def hk[M[_]] = ???
5+
6+
implicit def imp(x: X): Int = x.hashCode
7+
}

0 commit comments

Comments
 (0)