summaryrefslogtreecommitdiff
path: root/src/swing
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-08-09 14:10:22 -0700
committerPaul Phillips <paulp@improving.org>2012-08-09 14:32:51 -0700
commiteb2375cc5327293c708226e78f80a97cc780a12f (patch)
tree61a10ec88c12546ccf44dbe653fec42a8429d203 /src/swing
parentc0d5f0aaddc7bc309f84afd5d4f4b5c136c65816 (diff)
downloadscala-eb2375cc5327293c708226e78f80a97cc780a12f.tar.gz
scala-eb2375cc5327293c708226e78f80a97cc780a12f.tar.bz2
scala-eb2375cc5327293c708226e78f80a97cc780a12f.zip
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" <console>: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 <console>: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) } <console>: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.
Diffstat (limited to 'src/swing')
-rw-r--r--src/swing/scala/swing/ComboBox.scala2
-rw-r--r--src/swing/scala/swing/ListView.scala2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/swing/scala/swing/ComboBox.scala b/src/swing/scala/swing/ComboBox.scala
index c7a457d082..67e39cfe3b 100644
--- a/src/swing/scala/swing/ComboBox.scala
+++ b/src/swing/scala/swing/ComboBox.scala
@@ -182,7 +182,7 @@ class ComboBox[A](items: Seq[A]) extends Component with Publisher {
* of the component to its own defaults _after_ the renderer has been
* configured. That's Swing's principle of most suprise.
*/
- def renderer: ListView.Renderer[A] = ListView.Renderer.wrap(peer.getRenderer)
+ def renderer: ListView.Renderer[A] = ListView.Renderer.wrap[A](peer.getRenderer)
def renderer_=(r: ListView.Renderer[A]) { peer.setRenderer(r.peer) }
/* XXX: currently not safe to expose:
diff --git a/src/swing/scala/swing/ListView.scala b/src/swing/scala/swing/ListView.scala
index 282d24696e..22850bac42 100644
--- a/src/swing/scala/swing/ListView.scala
+++ b/src/swing/scala/swing/ListView.scala
@@ -216,7 +216,7 @@ class ListView[A] extends Component {
def adjusting = peer.getSelectionModel.getValueIsAdjusting
}
- def renderer: ListView.Renderer[A] = ListView.Renderer.wrap(peer.getCellRenderer)
+ def renderer: ListView.Renderer[A] = ListView.Renderer.wrap[A](peer.getCellRenderer)
def renderer_=(r: ListView.Renderer[A]) { peer.setCellRenderer(r.peer) }
def fixedCellWidth = peer.getFixedCellWidth