Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
- Added ExplainTypes compiler option to explain type errors in more
Browse files Browse the repository at this point in the history
  detail
- Added a minor level of detection for scala.Nothing and throw a
  IllegalArgumentException if it's picked up due to type inference
  failure (Added to MongoDBObject)
  • Loading branch information
bwmcadams committed Jul 29, 2010
1 parent d34697f commit 96f55f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions project/build/CasbahProject.scala
@@ -1,7 +1,7 @@
import sbt._

class CasbahProject(info: ProjectInfo) extends DefaultProject(info) with rsync.RsyncPublishing {
override def compileOptions = super.compileOptions ++ Seq(Unchecked, Deprecation)
class CasbahProject(info: ProjectInfo) extends DefaultProject(info) with rsync.RsyncPublishing with posterous.Publish {
override def compileOptions = super.compileOptions ++ Seq(Unchecked, ExplainTypes, Deprecation)

val scalaTime = "org.scala-tools" % "time" % "2.8.0-0.2-SNAPSHOT"

Expand Down
3 changes: 2 additions & 1 deletion project/plugins/Plugin.scala
@@ -1,7 +1,8 @@
class Plugins(info: sbt.ProjectInfo) extends sbt.PluginDefinition(info) {
val codaRepo = "Coda Hale's Repository" at "http://repo.codahale.com/"
val rsyncSBT = "com.codahale" % "rsync-sbt" % "0.1.0"

val posterousRepo = "t_repo" at "http://tristanhunt.com:8081/content/groups/public/"
val posterous = "net.databinder" % "posterous-sbt" % "0.1.6"
}

// vim: set ts=2 sw=2 sts=2 et:
7 changes: 5 additions & 2 deletions src/main/scala/mongodb/MongoDBObject.scala
Expand Up @@ -60,10 +60,13 @@ trait MongoDBObject extends Map[String, Object] with Logging {
case value => Some(value)
}

def apply[A : Manifest](key: String) = underlying.get(key).asInstanceOf[A]
def apply[A <% AnyRef : Manifest](key: String): A = {
require(manifest[A] != manifest[scala.Nothing], "Type inference failed; apply() requires an explicit type argument (e.g. dbObject[<ReturnType](\"someKey\") ) to function correctly.")
underlying.get(key).asInstanceOf[A]
}

/** Lazy utility method to allow typing without conflicting with Map's required get() method and causing ambiguity */
def getAs[A](key: String): Option[A] = underlying.get(key) match {
def getAs[A <% AnyRef : Manifest](key: String): Option[A] = underlying.get(key) match {
case null => None
case value => Some(value.asInstanceOf[A])
}
Expand Down

0 comments on commit 96f55f4

Please sign in to comment.