File tree Expand file tree Collapse file tree 5 files changed +48
-0
lines changed
src/compiler/scala/tools/nsc Expand file tree Collapse file tree 5 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -661,6 +661,7 @@ object Reporting {
661
661
LintIntDivToFloat ,
662
662
LintUniversalMethods ,
663
663
LintCloneable ,
664
+ LintOverload ,
664
665
LintNumericMethods
665
666
= lint()
666
667
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ trait Warnings {
229
229
val IntDivToFloat = LintWarning (" int-div-to-float" , " Warn when an integer division is converted (widened) to floating point: `(someInt / 2): Double`." )
230
230
val PatternShadow = LintWarning (" pattern-shadow" , " Pattern variable id is also a term in scope." )
231
231
val CloneableObject = LintWarning (" cloneable" , " Modules (objects) should not be Cloneable." )
232
+ val DubiousOverload = LintWarning (" overload" , " Overload differs only in an implicit parameter." )
232
233
233
234
def allLintWarnings = values.toSeq.asInstanceOf [Seq [LintWarning ]]
234
235
}
@@ -267,6 +268,7 @@ trait Warnings {
267
268
def lintIntDivToFloat = lint.contains(IntDivToFloat )
268
269
def warnPatternShadow = lint.contains(PatternShadow )
269
270
def warnCloneableObject = lint.contains(CloneableObject )
271
+ def warnDubiousOverload = lint.contains(DubiousOverload )
270
272
271
273
// The Xlint warning group.
272
274
val lint = MultiChoiceSetting (
Original file line number Diff line number Diff line change @@ -144,6 +144,20 @@ abstract class RefChecks extends Transform {
144
144
}
145
145
}
146
146
}
147
+ if (settings.warnDubiousOverload) {
148
+ val members = clazz.info.members
149
+ val implicitMembers = members.filter(_.tpe match { case mt : MethodType => mt.isImplicit case _ => false })
150
+ implicitMembers.foreach { sym =>
151
+ val alts = clazz.info.decl(sym.name).filter(_.paramss.isEmpty).alternatives
152
+ alts.foreach { alt =>
153
+ val usage = if (alt.isMethod && ! alt.isGetter) " Calls to parameterless" else " Usages of"
154
+ val impl = sym.defString
155
+ refchecksWarning(alt.pos,
156
+ s " $usage $alt will be easy to mistake for calls to $impl, which has a single implicit parameter list. " ,
157
+ WarningCategory .LintOverload )
158
+ }
159
+ }
160
+ }
147
161
148
162
// Check for doomed attempt to overload applyDynamic
149
163
if (clazz.isSubClass(DynamicClass ))
Original file line number Diff line number Diff line change
1
+ t7415.scala:10: warning: Calls to parameterless method foo will be easy to mistake for calls to def foo(implicit a: T): Int, which has a single implicit parameter list.
2
+ def foo = 0
3
+ ^
4
+ t7415.scala:14: warning: Usages of value foo will be easy to mistake for calls to def foo(implicit a: T): Int, which has a single implicit parameter list.
5
+ val foo = 0
6
+ ^
7
+ t7415.scala:18: warning: Usages of value foo will be easy to mistake for calls to def foo(implicit a: T): Int, which has a single implicit parameter list.
8
+ private[this] val foo = 42
9
+ ^
10
+ error: No warnings can be incurred under -Werror.
11
+ 3 warnings
12
+ 1 error
Original file line number Diff line number Diff line change
1
+ //> using options -Werror -Xlint:overload
2
+
3
+ trait T
4
+
5
+ trait Base {
6
+ def foo (implicit a : T ) = 0
7
+ }
8
+
9
+ trait Derived1 extends Base {
10
+ def foo = 0
11
+ }
12
+
13
+ trait Derived2 extends Base {
14
+ val foo = 0
15
+ }
16
+
17
+ class C extends Base {
18
+ private [this ] val foo = 42
19
+ }
You can’t perform that action at this time.
0 commit comments