Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit exception type parameters seem to Just Work - add tests #15

Open
lrytz opened this issue May 17, 2013 · 0 comments
Open

Explicit exception type parameters seem to Just Work - add tests #15

lrytz opened this issue May 17, 2013 · 0 comments
Labels

Comments

@lrytz
Copy link
Owner

lrytz commented May 17, 2013

feels like java :)

scala> import annotation.effects._
import annotation.effects._

scala> class E1 extends Exception
defined class E1

scala> trait Fun[A, B, E <: Exception] { def apply(a: A): B @throws[E] }
defined trait Fun

scala> def foo[E <: Exception](fun: Fun[Int, Int, E]): Int @throws[E] = fun(1)
foo: [E <: Exception](fun: Fun[Int,Int,E])Int @scala.annotation.effects.throws[E]

scala> foo(new Fun[Int, Int, Nothing] { def apply(x: Int) = x })
res1: Int @scala.annotation.effects.throws[Nothing] = 1

scala> foo(new Fun[Int, Int, E1] { def apply(x: Int) = x })
res2: Int @scala.annotation.effects.throws[Nothing] = 1

scala> foo(new Fun[Int, Int, Nothing] { def apply(x: Int) = throw new E1 })
<console>:14: error: overriding method apply in trait Fun of type (a: Int)Int @scala.annotation.effects.throws[Nothing];
 method apply has incompatible type
              foo(new Fun[Int, Int, Nothing] { def apply(x: Int) = throw new E1 })
                                                   ^

this one in fact does not seem to work:

scala> def bar = foo(new Fun[Int, Int, E1] { def apply(x: Int): Int @throws[E1] = x })
bar: Int @scala.annotation.effects.throws[Nothing]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant