diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-30 13:29:14 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-30 13:29:14 -0800 |
commit | 50f38393af6d5aee3739cc73fdd5c7d22361390a (patch) | |
tree | 795166dc94035a5d9bfa608a5d3cd2c9a10cd7d2 /src/compiler | |
parent | 0e578e693196f93b1ba4f972a2c96d468bef464a (diff) | |
parent | 327eea839e97e1d7cac92aa9cd61e3338d12cb12 (diff) | |
download | scala-50f38393af6d5aee3739cc73fdd5c7d22361390a.tar.gz scala-50f38393af6d5aee3739cc73fdd5c7d22361390a.tar.bz2 scala-50f38393af6d5aee3739cc73fdd5c7d22361390a.zip |
Merge pull request #3416 from retronym/topic/any-val-implicit
Prohibit views targeting AnyVal
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 91321d4700..847211945c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -137,10 +137,6 @@ trait Implicits { private val improvesCache = perRunCaches.newMap[(ImplicitInfo, ImplicitInfo), Boolean]() private val implicitSearchId = { var id = 1 ; () => try id finally id += 1 } - private def isInvalidConversionTarget(tpe: Type): Boolean = tpe match { - case Function1(_, out) => AnyRefClass.tpe <:< out - case _ => false - } private def isInvalidConversionSource(tpe: Type): Boolean = tpe match { case Function1(in, _) => in <:< NullClass.tpe case _ => false @@ -629,7 +625,8 @@ trait Implicits { // for instance, if we have `class C[T]` and `implicit def conv[T: Numeric](c: C[T]) = ???` // then Scaladoc will give us something of type `C[T]`, and it would like to know // that `conv` is potentially available under such and such conditions - case tree if isImplicitMethodType(tree.tpe) && !isScalaDoc => applyImplicitArgs(tree) + case tree if isImplicitMethodType(tree.tpe) && !isScalaDoc => + applyImplicitArgs(tree) case tree => tree } case _ => fallback @@ -1361,11 +1358,17 @@ trait Implicits { if (context.ambiguousErrors) context.issueAmbiguousError(AmbiguousImplicitTypeError(tree, msg)) } - if (isInvalidConversionTarget(pt)) { - maybeInvalidConversionError("the result type of an implicit conversion must be more specific than AnyRef") - result = SearchFailure + pt match { + case Function1(_, out) => + def prohibit(sym: Symbol) = if (sym.tpe <:< out) { + maybeInvalidConversionError(s"the result type of an implicit conversion must be more specific than ${sym.name}") + result = SearchFailure + } + prohibit(AnyRefClass) + if (settings.isScala211) prohibit(AnyValClass) + case _ => false } - else if (settings.isScala211 && isInvalidConversionSource(pt)) { + if (settings.isScala211 && isInvalidConversionSource(pt)) { maybeInvalidConversionError("an expression of type Null is ineligible for implicit conversion") result = SearchFailure } |