-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0b6b20
commit 4bdcaa8
Showing
5 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Test { | ||
trait A[+T] | ||
class B[T] extends A[T] | ||
class C[T] extends B[Any] with A[T] | ||
|
||
def foo[T](c: C[T]): Unit = c match { | ||
case _: B[T] => // error | ||
} | ||
|
||
def bar[T](b: B[T]): Unit = b match { | ||
case _: A[T] => | ||
} | ||
|
||
def quux[T](a: A[T]): Unit = a match { | ||
case _: B[T] => // error | ||
} | ||
|
||
quux(new C[Int]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
object Test { | ||
trait Foo | ||
case class One[+T](fst: T) | ||
|
||
def bad[T <: Foo](e: One[T])(x: T) = e match { | ||
case foo: One[a] => | ||
x.isInstanceOf[a] // error | ||
val y: Any = ??? | ||
y.isInstanceOf[a] // error | ||
} | ||
} | ||
|
||
object Test2 { | ||
case class One[T](fst: T) | ||
|
||
def bad[T](e: One[T])(x: T) = e match { | ||
case foo: One[a] => | ||
x.isInstanceOf[a] // error | ||
val y: Any = ??? | ||
y.isInstanceOf[a] // error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
import scala.util.control.NonFatal | ||
object p { | ||
|
||
// test parametric case classes, which synthesis `canEqual` and `equals` | ||
enum Result[+T, +E] { | ||
case OK [T](x: T) extends Result[T, Nothing] | ||
case Err[E](e: E) extends Result[Nothing, E] | ||
} | ||
|
||
type Try[T] = Result[T, Throwable] | ||
object Try { | ||
def apply[T](x: => T): Try[T] = | ||
try Result.OK(x) | ||
catch { | ||
case NonFatal(ex) => Result.Err(ex) | ||
} | ||
} | ||
|
||
def foo(x: Any): Boolean = | ||
x.isInstanceOf[List[String]] // error | ||
} |