8000 Improvements · scala/scala@2b7e0fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b7e0fe

Browse files
som-snyttlrytz
authored andcommitted
Improvements
1 parent e7da16c commit 2b7e0fe

File tree

13 files changed

+82
-26
lines changed

13 files changed

+82
-26
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ trait ParsersCommon extends ScannersCommon {
4141
// same time; use Parser.unit instead
4242
import global.{currentUnit => _, _}
4343

44-
def newLiteral(value: Any) = Literal(Constant(value))
44+
def newLiteral(const: Any) = Literal(Constant(const))
4545
def literalUnit = gen.mkSyntheticUnit()
4646

4747
/** This is now an abstract class, only to work around the optimizer:

src/compiler/scala/tools/nsc/backend/jvm/BCodeIdiomatic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ abstract class BCodeIdiomatic {
318318
} // end of emitT2T()
319319

320320
// can-multi-thread
321-
final def boolconst(@deprecatedName b: Boolean): Unit = {
321+
final def boolconst(b: Boolean): Unit = {
322322
if (b) emit(Opcodes.ICONST_1)
323323
else emit(Opcodes.ICONST_0)
324324
}

src/compiler/scala/tools/nsc/tasty/bridge/ContextOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ trait ContextOps { self: TastyUniverse =>
7979
???
8080
}
8181

82-
@inline final def assert(@deprecatedName assertion: Boolean, msg: => Any): Unit =
82+
@inline final def assert(assertion: Boolean, msg: => Any): Unit =
8383
u.assert(assertion, msg)
8484

85-
@inline final def assert(@deprecatedName assertion: Boolean): Unit =
85+
@inline final def assert(assertion: Boolean): Unit =
8686
u.assert(assertion, "")
8787

8888
private final def findObject(owner: Symbol, name: u.Name): Symbol = {

src/compiler/scala/tools/nsc/transform/async/TransformUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private[async] trait TransformUtils extends AsyncTransformStates {
8989

9090
def literalUnit: Tree = Literal(Constant(())).setType(definitions.UnitTpe) // a def to avoid sharing trees
9191
def literalBoxedUnit: Tree = gen.mkAttributedRef(definitions.BoxedUnit_UNIT)
92-
def literalBool(@deprecatedName b: Boolean): Tree = Literal(Constant(b)).setType(definitions.BooleanTpe)
92+
def literalBool(b: Boolean): Tree = Literal(Constant(b)).setType(definitions.BooleanTpe)
9393

9494
def isLiteralUnit(t: Tree): Boolean = t match {
9595
case Literal(Constant(())) => true

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,19 +1713,45 @@ abstract class RefChecks extends Transform {
17131713
if (!inPattern) {
17141714
checkImplicitViewOptionApply(tree.pos, fn, args)
17151715
checkSensible(tree.pos, fn, args) // TODO: this should move to preEraseApply, as reasoning about runtime semantics makes more sense in the JVM type system
1716+
checkNamedBooleanArgs(fn, args)
17161717
}
1717-
val sym = fn.symbol
1718-
if (settings.lintNamedBooleans && sym.ne(null) && sym.ne(NoSymbol) && !sym.isJavaDefined)
1719-
foreach2(args, sym.paramss.head)((arg, param) => arg match {
1720-
case t @ Literal(Constant(_: Boolean)) if
1721-
t.hasAttachment[UnnamedArg.type] && param.tpe.typeSymbol == BooleanClass && !param.deprecatedParamName.contains(nme.NO_NAME) =>
1722-
runReporting.warning(t.pos, s"Boolean literals should be passed using named argument syntax for parameter ${param.name}.", WarningCategory.LintNamedBooleans, sym)
1723-
case _ =>
1724-
})
17251718
currentApplication = tree
17261719
tree
17271720
}
17281721

1722+
/** Check that boolean literals are passed as named args.
1723+
* The rule is enforced when the type of the parameter is `Boolean`.
1724+
* The rule is relaxed when the method has exactly one boolean parameter
1725+
* and it is the first parameter, such as `assert(false, msg)`.
1726+
*/
1727+
private def checkNamedBooleanArgs(fn: Tree, args: List[Tree]): Unit = {
1728+
val sym = fn.symbol
1729+
def applyDepth: Int = {
1730+
def loop(t: Tree, d: Int): Int =
1731+
t match {
1732+
case Apply(f, _) => loop(f, d+1)
1733+
case _ => d
1734+
}
1735+
loop(fn, 0)
1736+
}
1737+
def isAssertParadigm(params: List[Symbol]): Boolean = !sym.isConstructor && !sym.isCaseApplyOrUnapply && {
1738+
params match {
1739+
case h :: t => h.tpe == BooleanTpe && !t.exists(_.tpe == BooleanTpe)
1740+
case _ => false
1741+
}
1742+
}
1743+
if (settings.lintNamedBooleans && !sym.isJavaDefined && !args.isEmpty) {
1744+
val params = sym.paramLists(applyDepth)
1745+
if (!isAssertParadigm(params))
1746+
foreach2(args, params)((arg, param) => arg match {
1747+
case Literal(Constant(_: Boolean))
1748+
if arg.hasAttachment[UnnamedArg.type] && param.tpe.typeSymbol == BooleanClass && !param.deprecatedParamName.contains(nme.NO_NAME) =>
1749+
runReporting.warning(arg.pos, s"Boolean literals should be passed using named argument syntax for parameter ${param.name}.", WarningCategory.LintNamedBooleans, sym)
1750+
case _ =>
1751+
})
1752+
}
1753+
}
1754+
17291755
private def transformSelect(tree: Select): Tree = {
17301756
val Select(qual, name) = tree
17311757
val sym = tree.symbol

src/library/scala/Array.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ object Array {
204204

205205
/** Creates an array of `Boolean` objects */
206206
// Subject to a compiler optimization in Cleanup, see above.
207-
def apply(@deprecatedName x: Boolean, xs: Boolean*): Array[Boolean] = {
207+
def apply(x: Boolean, xs: Boolean*): Array[Boolean] = {
208208
val array = new Array[Boolean](xs.length + 1)
209209
array(0) = x
210210
val iterator = xs.iterator

src/library/scala/Predef.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ object Predef extends LowPriorityImplicits {
259259
* @group assertions
260260
*/
261261
@elidable(ASSERTION)
262-
def assert(@deprecatedName assertion: Boolean): Unit = {
262+
def assert(assertion: Boolean): Unit = {
263263
if (!assertion)
264264
throw new java.lang.AssertionError("assertion failed")
265265
}
@@ -274,7 +274,7 @@ object Predef extends LowPriorityImplicits {
274274
* @group assertions
275275
*/
276276
@elidable(ASSERTION) @inline
277-
final def assert(@deprecatedName assertion: Boolean, message: => Any): Unit = {
277+
final def assert(assertion: Boolean, message: => Any): Unit = {
278278
if (!assertion)
279279
throw new java.lang.AssertionError("assertion failed: "+ message)
280280
}

src/library/scala/collection/Iterator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
207207
* @note This method is mutually exclusive with `withPadding`.
208208
* @group Configuration
209209
*/
210-
def withPartial(@deprecatedName x: Boolean): this.type = {
210+
def withPartial(x: Boolean): t 212A his.type = {
211211
partial = x
212212
padding = null
213213
this

src/reflect/scala/reflect/internal/SymbolTable.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ abstract class SymbolTable extends macros.Universe
153153
}
154154

155155
@inline
156-
final def assert(@deprecatedName assertion: Boolean, message: => Any): Unit =
156+
final def assert(assertion: Boolean, message: => Any): Unit =
157157
if (!assertion) throwAssertionError(message)
158158

159159
@deprecated("consider supplying an explanatory message", since = "2.12.5")
160-
final def assert(@deprecatedName assertion: Boolean): Unit = assert(assertion, "")
160+
final def assert(assertion: Boolean): Unit = assert(assertion, "")
161161

162162
@inline
163163
final def require(requirement: Boolean, message: => Any): Unit =

src/testkit/scala/tools/testkit/AllocationTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ trait AllocationTest {
6767
import AllocationTest._
6868

6969
/** Asserts whether it's expected for `a == b` to allocate memory. */
70-
def nonAllocatingEqual(@deprecatedName expected: Boolean, a: AnyRef, b: AnyRef): Unit = {
70+
def nonAllocatingEqual(expected: Boolean, a: AnyRef, b: AnyRef): Unit = {
7171
assertEquals(expected, nonAllocating(Boolean.box(a == b)))
7272
}
7373

0 commit comments

Comments
 (0)
0