-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ylint to warn strict else warn multiple boolean lits
- Loading branch information
Showing
5 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
named-booleans-relaxed.scala:22: warning: Boolean literals should be passed using named argument syntax for parameter x. | ||
val x0 = c.f(17, true, false) // warn | ||
^ | ||
named-booleans-relaxed.scala:22: warning: Boolean literals should be passed using named argument syntax for parameter y. | ||
val x0 = c.f(17, true, false) // warn | ||
^ | ||
named-booleans-relaxed.scala:44: warning: Boolean literals should be passed using named argument syntax for parameter cond. | ||
c.uncheck(false, "OK", true) | ||
^ | ||
named-booleans-relaxed.scala:44: warning: Boolean literals should be passed using named argument syntax for parameter flag. | ||
c.uncheck(false, "OK", true) | ||
^ | ||
named-booleans-relaxed.scala:63: warning: Boolean literals should be passed using named argument syntax for parameter isKlazz. | ||
def test = Klazz(true, false) // warn case class apply as for ctor | ||
^ | ||
named-booleans-relaxed.scala:63: warning: Boolean literals should be passed using named argument syntax for parameter isWarnable. | ||
def test = Klazz(true, false) // warn case class apply as for ctor | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
6 warnings | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//> using options -Werror -Xlint:named-booleans | ||
|
||
class C { | ||
def f(n: Int = 42, x: Boolean, y: Boolean) = if (x && y) n else 0 | ||
|
||
def g(x: Any) = | ||
x match { | ||
case (true, false) => 0 | ||
case _ => 1 | ||
} | ||
var b = false | ||
def fs(n: Int)(s: String, b: Boolean) = if (b) s*n else s | ||
def gs[A](n: Int)(s: A, b: Boolean) = if (b) s.toString*n else s.toString | ||
|
||
def check(cond: Boolean, msg: => String) = if (cond) println(msg) | ||
def uncheck(cond: Boolean, msg: => String, flag: Boolean) = if (cond && flag) println(msg) | ||
} | ||
|
||
object Test extends App { | ||
val c = new C | ||
val b = false | ||
val x0 = c.f(17, true, false) // warn | ||
val x1 = c.f(17, true, b) // nowarn | ||
val x2 = c.f(y = b, n = 17, x = true) // nowarn | ||
c.b = true | ||
val y = Some(false) | ||
val z = Option(false) | ||
val w = (true, false) | ||
val v = c g true // nowarn infix | ||
|
||
val s = collection.mutable.Set.empty[String] | ||
def mutateS(): Unit = s("updater") = true | ||
//def updateS(): Unit = s.update("updater", true) | ||
|
||
val m = collection.mutable.Map.empty[String, true] | ||
def mutateM(): Unit = m("updater") = true | ||
|
||
val ss = c.fs(42)("hello", true) | ||
val tt = c.gs(42)("hello", true) | ||
|
||
def f(g: Boolean => Option[Boolean]) = g(true).getOrElse(false) | ||
|
||
c.check(true, "OK") | ||
c.uncheck(false, "OK", true) | ||
} | ||
|
||
class Arrays { | ||
def test = Array(true, false, true) | ||
} | ||
|
||
class Tuples { | ||
def test = (true, false, true) | ||
} | ||
|
||
class Functions { | ||
val f: Boolean => Boolean = identity | ||
def test = f(true) | ||
} | ||
|
||
case class Klazz(isKlazz: Boolean, isWarnable: Boolean) | ||
|
||
class Klazzy { | ||
def test = Klazz(true, false) // warn case class apply as for ctor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters