diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-11-03 16:19:46 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-11-03 16:27:15 +0100 |
commit | 0bcb9e9169146e3f589c6c9f65cc4a5523b78120 (patch) | |
tree | 6fb37c99eb90de4e13850edbfddfcb2dca6be0ea /src/compiler | |
parent | 0475fbd6e0cad15460d87eda52c9487f7ff171d3 (diff) | |
download | scala-0bcb9e9169146e3f589c6c9f65cc4a5523b78120.tar.gz scala-0bcb9e9169146e3f589c6c9f65cc4a5523b78120.tar.bz2 scala-0bcb9e9169146e3f589c6c9f65cc4a5523b78120.zip |
SI-6567 Warning for Option(implicitView(foo))
I've seen the reported problem before in the wild. It seems
worthy of a special warning, so long as we advocate Option.apply
as an alternative to `if (x == null) Some(x) else None`.
It is behind -Xlint at the moment, an option that could do with
some promotion.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index c04a8661b2..60bed95b9e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1051,6 +1051,12 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans def apply(tp: Type) = mapOver(tp).normalize } + def checkImplicitViewOptionApply(pos: Position, fn: Tree, args: List[Tree]): Unit = if (settings.lint.value) (fn, args) match { + case (tap@TypeApply(fun, targs), List(view: ApplyImplicitView)) if fun.symbol == Option_apply => + unit.warning(pos, s"Suspicious application of an implicit view (${view.fun}) in the argument to Option.apply.") // SI-6567 + case _ => + } + def checkSensible(pos: Position, fn: Tree, args: List[Tree]) = fn match { case Select(qual, name @ (nme.EQ | nme.NE | nme.eq | nme.ne)) if args.length == 1 => def isReferenceOp = name == nme.eq || name == nme.ne @@ -1535,7 +1541,10 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans case Apply(fn, args) => // sensicality should be subsumed by the unreachability/exhaustivity/irrefutability analyses in the pattern matcher - if (!inPattern) checkSensible(tree.pos, fn, args) + if (!inPattern) { + checkImplicitViewOptionApply(tree.pos, fn, args) + checkSensible(tree.pos, fn, args) + } currentApplication = tree tree } |