Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10657 from dwijnand/fruitless-type-test
Fix lack of incompatible type warnings
- Loading branch information
Showing
6 changed files
with
68 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
patmat-sealed-reachable.scala:14: warning: fruitless type test: a value of type Option[Int] cannot also be a SomeClass | ||
def b(c: Option[Int]) = c match { case _: SomeClass =>; case _ => } | ||
^ | ||
patmat-sealed-reachable.scala:13: warning: fruitless type test: a value of type Option[Int] cannot also be a SealedTrait | ||
def a(c: Option[Int]) = c match { case _: SealedTrait =>; case _ => } | ||
^ | ||
patmat-sealed-reachable.scala:15: warning: fruitless type test: a value of type Option[Int] cannot also be a UnsealedTrait | ||
def c(c: Option[Int]) = c match { case _: UnsealedTrait =>; case _ => } | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
3 warnings | ||
1 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// scalac: -Werror | ||
|
||
// aka t12438.scala | ||
|
||
sealed trait SealedTrait | ||
class SomeClass | ||
trait UnsealedTrait | ||
|
||
sealed abstract class O | ||
class O1 extends O | ||
|
||
class Test { | ||
def a(c: Option[Int]) = c match { case _: SealedTrait =>; case _ => } | ||
def b(c: Option[Int]) = c match { case _: SomeClass =>; case _ => } | ||
def c(c: Option[Int]) = c match { case _: UnsealedTrait =>; case _ => } | ||
// O1 is not final , so there could be a value of type O1 with UnsealedTrait | ||
def nowarn(c: O) = c match { case _: UnsealedTrait =>; case _ => } | ||
} |
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,6 @@ | ||
t12304.scala:10: warning: fruitless type test: a value of type Foo cannot also be a Bar | ||
m.collect { case (_, bar: Bar) =>} | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
1 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// scalac: -Werror | ||
|
||
// variant of pos/t12304 | ||
// that does warn as desired | ||
|
||
class Foo; class Bar | ||
class Test { | ||
def t1: Unit = { | ||
val m = Map(1 -> new Foo) | ||
m.collect { case (_, bar: Bar) =>} | ||
} | ||
} |
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,15 @@ | ||
// scalac: -Werror | ||
|
||
class Foo | ||
class Test { | ||
def t1: Unit = { | ||
val m: Map[String, Map[String, Foo]] = Map("outer" -> Map("inner" -> new Foo)) | ||
m.collect { case (_, foo: Foo) => "This should be type error" } | ||
// no: | ||
// class Foo isn't final | ||
// Map is an unsealed trait | ||
// so it's possible to define: | ||
// class Bar extends Foo with Map[...] | ||
// so the compiler is right not to warn | ||
} | ||
} |