Skip to content

Commit

Permalink
Easy suppression of deprecated paren syntax warning
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Feb 28, 2023
1 parent 956f58b commit 4344632
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/compiler/scala/tools/nsc/Reporting.scala
Expand Up @@ -333,7 +333,7 @@ object Reporting {
.toLowerCase
}

def includes(o: WarningCategory): Boolean = this eq o
def includes(msg: Message): Boolean = this eq msg.category
def summaryCategory: WarningCategory = this
}

Expand All @@ -354,7 +354,7 @@ object Reporting {
object JavaSource extends WarningCategory; add(JavaSource)

sealed trait Other extends WarningCategory { override def summaryCategory: WarningCategory = Other }
object Other extends Other { override def includes(o: WarningCategory): Boolean = o.isInstanceOf[Other] }; add(Other)
object Other extends Other { override def includes(msg: Message): Boolean = msg.category.isInstanceOf[Other] }; add(Other)
object OtherShadowing extends Other; add(OtherShadowing)
object OtherPureStatement extends Other; add(OtherPureStatement)
object OtherMigration extends Other; add(OtherMigration)
Expand All @@ -365,15 +365,15 @@ object Reporting {
object OtherImplicitType extends Other; add(OtherImplicitType)

sealed trait WFlag extends WarningCategory { override def summaryCategory: WarningCategory = WFlag }
object WFlag extends WFlag { override def includes(o: WarningCategory): Boolean = o.isInstanceOf[WFlag] }; add(WFlag)
object WFlag extends WFlag { override def includes(msg: Message): Boolean = msg.category.isInstanceOf[WFlag] }; add(WFlag)
object WFlagDeadCode extends WFlag; add(WFlagDeadCode)
object WFlagExtraImplicit extends WFlag; add(WFlagExtraImplicit)
object WFlagNumericWiden extends WFlag; add(WFlagNumericWiden)
object WFlagSelfImplicit extends WFlag; add(WFlagSelfImplicit)
object WFlagValueDiscard extends WFlag; add(WFlagValueDiscard)

sealed trait Unused extends WarningCategory { override def summaryCategory: WarningCategory = Unused }
object Unused extends Unused { override def includes(o: WarningCategory): Boolean = o.isInstanceOf[Unused] }; add(Unused)
object Unused extends Unused { override def includes(msg: Message): Boolean = msg.category.isInstanceOf[Unused] }; add(Unused)
object UnusedImports extends Unused; add(UnusedImports)
object UnusedPatVars extends Unused; add(UnusedPatVars)
object UnusedPrivates extends Unused; add(UnusedPrivates)
Expand All @@ -382,7 +382,7 @@ object Reporting {
object UnusedNowarn extends Unused; add(UnusedNowarn)

sealed trait Lint extends WarningCategory { override def summaryCategory: WarningCategory = Lint }
object Lint extends Lint { override def includes(o: WarningCategory): Boolean = o.isInstanceOf[Lint] }; add(Lint)
object Lint extends Lint { override def includes(msg: Message): Boolean = msg.category.isInstanceOf[Lint] }; add(Lint)
object LintAdaptedArgs extends Lint; add(LintAdaptedArgs)
object LintNullaryUnit extends Lint; add(LintNullaryUnit)
object LintInaccessible extends Lint; add(LintInaccessible)
Expand Down Expand Up @@ -410,14 +410,18 @@ object Reporting {
object LintPerformance extends Lint; add(LintPerformance)

sealed trait Feature extends WarningCategory { override def summaryCategory: WarningCategory = Feature }
object Feature extends Feature { override def includes(o: WarningCategory): Boolean = o.isInstanceOf[Feature] }; add(Feature)
object Feature extends Feature { override def includes(msg: Message): Boolean = msg.category.isInstanceOf[Feature] }; add(Feature)
object FeatureDynamics extends Feature; add(FeatureDynamics)
object FeatureExistentials extends Feature; add(FeatureExistentials)
object FeatureHigherKinds extends Feature; add(FeatureHigherKinds)
object FeatureImplicitConversions extends Feature; add(FeatureImplicitConversions)
object FeaturePostfixOps extends Feature; add(FeaturePostfixOps)
object FeatureReflectiveCalls extends Feature; add(FeatureReflectiveCalls)
object FeatureMacros extends Feature; add(FeatureMacros)

object FunctionParens extends WarningCategory {
override def includes(msg: Message): Boolean = (msg.category eq Deprecation) && msg.msg.startsWith("parentheses are required around the parameter of a lambda")
}; add(FunctionParens)
}

sealed trait Version {
Expand Down Expand Up @@ -492,7 +496,7 @@ object Reporting {
}

final case class Category(cat: WarningCategory) extends MessageFilter {
def matches(message: Message): Boolean = cat.includes(message.category)
def matches(message: Message): Boolean = cat.includes(message)
}

final case class MessagePattern(pattern: Regex) extends MessageFilter {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Expand Up @@ -783,7 +783,7 @@ self =>
if (currentRun.isScala3)
syntaxError(tree.pos.point, msg)
else
deprecationWarning(tree.pos.point, msg, "2.13.11")
deprecationWarning(tree.pos.point, s"$msg (silence with -Wconf:cat=function-parens:s)", "2.13.11")
List(convertToParam(tree))
case _ => List(convertToParam(tree))
}
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/parens-for-params.check
@@ -1,4 +1,4 @@
parens-for-params.scala:5: warning: parentheses are required around the parameter of a lambda
parens-for-params.scala:5: warning: parentheses are required around the parameter of a lambda (silence with -Wconf:cat=function-parens:s)
x: Int => x * 2
^
error: No warnings can be incurred under -Werror.
Expand Down
10 changes: 10 additions & 0 deletions test/files/pos/parens-for-params-silent.scala
@@ -0,0 +1,10 @@
// scalac: -Werror -Xlint -Wconf:cat=function-parens:s

class C {
def f = {
x: Int => x * 2
}
def g = {
(x: Int) => x * 2
}
}

0 comments on commit 4344632

Please sign in to comment.