From eb2375cc5327293c708226e78f80a97cc780a12f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 9 Aug 2012 14:10:22 -0700 Subject: Warn when Any or AnyVal is inferred. For the very small price of annotating types as Any/AnyVal in those cases where we wish to use them, we can obtain useful warnings. I made trunk clean against this warning and found several bugs or at least suboptimalities in the process. I put the warning behind -Xlint for the moment, but I think this belongs on by default, even for this alone: scala> List(1, 2, 3) contains "a" :8: warning: a type was inferred to be `Any`; this may indicate a programming error. List(1, 2, 3) contains "a" ^ res0: Boolean = false Or this punishment meted out by SI-4042: scala> 1l to 5l contains 5 :8: warning: a type was inferred to be `AnyVal`; this may indicate a programming error. 1l to 5l contains 5 ^ res0: Boolean = false A different situation where this arises, which I have seen variations of many times: scala> class A[T](default: T) { def get(x: => Option[T]) = x getOrElse Some(default) } :7: warning: a type was inferred to be `Any`; this may indicate a programming error. class A[T](default: T) { def get(x: => Option[T]) = x getOrElse Some(default) } ^ // Oops, this was what I meant scala> class A[T](default: T) { def get(x: => Option[T]) = x getOrElse default } defined class A Harder to avoid spurious warnings when "Object" is inferred. --- src/continuations/library/scala/util/continuations/package.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/continuations') diff --git a/src/continuations/library/scala/util/continuations/package.scala b/src/continuations/library/scala/util/continuations/package.scala index 641f4594e4..93238d50e1 100644 --- a/src/continuations/library/scala/util/continuations/package.scala +++ b/src/continuations/library/scala/util/continuations/package.scala @@ -167,7 +167,7 @@ package object continuations { } def shiftUnitR[A,B](x: A): ControlContext[A,B,B] = { - new ControlContext(null, x) + new ControlContext[A, B, B](null, x) } /** -- cgit v1.2.3