-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make unchecked cases non-@unchecked
and non-unreachable
#16958
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
-- Error: tests/neg/i16451.scala:13:9 ---------------------------------------------------------------------------------- | ||
13 | case x: Wrapper[Color.Red.type] => Some(x) // error | ||
| ^ | ||
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] | ||
-- Error: tests/neg/i16451.scala:21:9 ---------------------------------------------------------------------------------- | ||
21 | case x: Wrapper[Color.Red.type] => Some(x) // error | ||
| ^ | ||
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Any | ||
-- Error: tests/neg/i16451.scala:25:9 ---------------------------------------------------------------------------------- | ||
25 | case x: Wrapper[Color.Red.type] => Some(x) // error | ||
| ^ | ||
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] | ||
-- Error: tests/neg/i16451.scala:29:9 ---------------------------------------------------------------------------------- | ||
29 | case x: Wrapper[Color.Red.type] => Some(x) // error | ||
| ^ | ||
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from A1 | ||
-- Error: tests/neg/i16451.scala:34:11 --------------------------------------------------------------------------------- | ||
34 | case x: Wrapper[Color.Red.type] => x // error | ||
| ^ | ||
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] | ||
-- Error: tests/neg/i16451.scala:39:11 --------------------------------------------------------------------------------- | ||
39 | case x: Wrapper[Color.Red.type] => x // error | ||
| ^ | ||
|the type test for Wrapper[(Color.Red : Color)] cannot be checked at runtime because its type arguments can't be determined from Wrapper[Color] |
This file contains hidden or 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,44 @@ | ||
// scalac: -Werror | ||
enum Color: | ||
case Red, Green | ||
//sealed trait Color | ||
//object Color: | ||
// case object Red extends Color | ||
// case object Green extends Color | ||
|
||
case class Wrapper[A](value: A) | ||
|
||
object Test: | ||
def test_correct(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match | ||
case x: Wrapper[Color.Red.type] => Some(x) // error | ||
case null => None | ||
|
||
def test_different(x: Wrapper[Color]): Option[Wrapper[Color]] = x match | ||
case x @ Wrapper(_: Color.Red.type) => Some(x) | ||
case x @ Wrapper(_: Color.Green.type) => None | ||
|
||
def test_any(x: Any): Option[Wrapper[Color.Red.type]] = x match | ||
case x: Wrapper[Color.Red.type] => Some(x) // error | ||
case _ => None | ||
|
||
def test_wrong(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] = x match | ||
case x: Wrapper[Color.Red.type] => Some(x) // error | ||
case null => None | ||
|
||
def t2[A1 <: Wrapper[Color]](x: A1): Option[Wrapper[Color.Red.type]] = x match | ||
case x: Wrapper[Color.Red.type] => Some(x) // error | ||
case null => None | ||
|
||
def test_wrong_seq(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] = | ||
xs.collect { | ||
case x: Wrapper[Color.Red.type] => x // error | ||
} | ||
|
||
def test_wrong_seq2(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] = | ||
xs.collect { x => x match | ||
case x: Wrapper[Color.Red.type] => x // error | ||
} | ||
|
||
def main(args: Array[String]): Unit = | ||
println(test_wrong_seq(Seq(Wrapper(Color.Red), Wrapper(Color.Green)))) | ||
// outputs: List(Wrapper(Red), Wrapper(Green)) |
This file contains hidden or 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,34 @@ | ||
// scalac: -Werror | ||
abstract class Namer: | ||
private enum CanForward: | ||
case Yes | ||
case No(whyNot: String) | ||
case Skip // for members that have never forwarders | ||
|
||
class Mbr | ||
private def canForward(mbr: Mbr): CanForward = CanForward.Yes | ||
|
||
private def applyOrElse[A1 <: CanForward, B1 >: String](x: A1, default: A1 => B1): B1 = x match | ||
case CanForward.No(whyNot @ _) => whyNot | ||
case _ => "" | ||
|
||
def addForwardersNamed(mbrs: List[Mbr]) = | ||
val reason = mbrs.map(canForward).collect { | ||
case CanForward.No(whyNot) => whyNot | ||
}.headOption.getOrElse("") | ||
|
||
class ClassCompleter: | ||
def addForwardersNamed(mbrs: List[Mbr]) = | ||
val reason = mbrs.map(canForward).collect { | ||
case CanForward.No(whyNot) => whyNot | ||
}.headOption.getOrElse("") | ||
|
||
private def exportForwarders = | ||
def addForwardersNamed(mbrs: List[Mbr]) = | ||
val reason = mbrs.map(canForward).collect { | ||
case CanForward.No(whyNot) => whyNot | ||
}.headOption.getOrElse("") | ||
if mbrs.size == 4 then | ||
val reason = mbrs.map(canForward).collect { | ||
case CanForward.No(whyNot) => whyNot | ||
}.headOption.getOrElse("") |
This file contains hidden or 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 | ||
object DiffUtil: | ||
private sealed trait Patch | ||
private final case class Unmodified(str: String) extends Patch | ||
private final case class Modified(original: String, str: String) extends Patch | ||
private final case class Deleted(str: String) extends Patch | ||
private final case class Inserted(str: String) extends Patch | ||
|
||
private def test(diff: Array[Patch]) = | ||
diff.collect { | ||
case Unmodified(str) => str | ||
case Inserted(str) => s"+$str" | ||
case Modified(orig, str) => s"{$orig,$str}" | ||
case Deleted(str) => s"-$str" | ||
}.mkString |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.