import scala.reflect.runtime.universe.TypeTag import scala.annotation.implicitNotFound @implicitNotFound("Sorry, type inference was unable to figure out the type. You need to provide it explicitly.") trait NotNothing[T] object NotNothing { private val evidence: NotNothing[Any] = new Object with NotNothing[Any] implicit def notNothingEvidence[T](implicit n: T =:= T): NotNothing[T] = evidence.asInstanceOf[NotNothing[T]] } def inject[T](implicit tt: TypeTag[T], nn: NotNothing[T]) = tt.toString inject // :12: error: Sorry, type inference was unable to figure out the type. You need to provide it explicitly. // inject // ^ inject[Nothing] // :12: error: Sorry, type inference was unable to figure out the type. You need to provide it explicitly. // inject[Nothing] // ^ val foo: String = inject // :11: error: Sorry, type inference was unable to figure out the type. You need to provide it explicitly. // val foo: String = inject // ^ inject[String] // res6: String = TypeTag[String] inject[Int] // res7: String = TypeTag[Int]