case class Failure(ex: Exception) extends Try[Nothing]
final case class Failure[+T](exception: Throwable) extends Try[T]
case None => ... // Compiles
case Failure => ... // Does not compile: "pattern type is incompatible with expected type"
case Failure[_] => ... // Compiles, but is unintuitive when working with None previously
case f: Failure[_] => p complete f.asInstanceOf[Failure[(T, U)]]
case f: Failure => p complete f
def get: Nothing
def get: T
Hi Christoph,
The only reason this hasn't been done before is due to backwards compatibility.
--
Cheers,
√
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
scala> def orDefault[A](o: Option[A]) = o match { case Some(a) => a; case _ => null.asInstanceOf[A] }
orDefault: [A](o: Option[A])A
scala> val opt: Option[Int] = None
opt: Option[Int] = None
scala> orDefault(opt)
res0: Int = 0 // Got it because we specified Option[Int]
scala> val opt3 = None
opt3: None.type = None
scala> val res: Int = orDefault(opt3)
res: Int = 0 // Got it because we specified our expected class
scala> orDefault(opt3)
java.lang.NullPointerException
...
scala> def default[A]() = null.asInstanceOf[A]
default: [A]()A
scala> opt.getOrElse(default())
java.lang.NullPointerException // Compiler can't infer Int
...
scala> opt.getOrElse(default[Int]()) // Manually specifing the default type works...
res8: Int = 0
def getOrElse[B >: A](default: => B): B
// This can btw lead to unexpected things like:
scala> Some(1L) getOrElse(0)
res5: AnyVal = 1 // Note the type isn't Long, but AnyVal
Hi Christoph,
The only reason this hasn't been done before is due to backwards compatibility.
We're also applying final touches to scala.meta to make it fully applicable to these kinds of tasks. If someone would be interested in lending a hand, please let me know, and I'll elaborate.
On Friday, May 15, 2015 at 9:15:34 AM UTC+2, Samuel Grütter wrote:
On Friday, May 15, 2015 at 12:33:30 AM UTC+2, Simon Schäfer wrote:
On 05/14/2015 11:33 PM, Simon Ochsenreither wrote:
> I agree! I think we could tackle this as soon as those
> source-rewriting tools are finally announced as available and stable...
I wonder: Has anyone even started working on such a tool?
Yes, I have, see https://github.com/samuelgruetter/srewrite
It's still in a very early phase, but we already used it to import the tests from Scala 2 into dotty (see PRs https://github.com/lampepfl/dotty/pull/294 and https://github.com/lampepfl/dotty/pull/558).
So far it only makes changes required by differences in the language, but it could easily be extended to also make changes required by differences in the library.
--
There doesn't seem to be much that can be done about the issue without causing compatibility problems, but here's the issue I created last year: