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
867f63a
commit d1f40cd
Showing
11 changed files
with
164 additions
and
41 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
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,13 @@ | ||
t12240.scala:21: warning: match may not be exhaustive. | ||
def guardedNonExhaustive(x: Int) = x match { | ||
^ | ||
t12240.scala:25: warning: match may not be exhaustive. | ||
def guardedSeqNonExhaustive(x: Int) = x match { | ||
^ | ||
t12240.scala:32: warning: match may not be exhaustive. | ||
It would fail on the following input: Vector1() | ||
def reported(v: Vector[String]) = v match { | ||
^ | ||
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,38 @@ | ||
// scalac: -Xfatal-warnings -Xlint:strict-unsealed-patmat | ||
// | ||
|
||
object Test { | ||
|
||
//see also pos/t12240.scala | ||
|
||
class IrrefutableNameBasedResult[Result](r: Result) { | ||
def isEmpty: false = false | ||
def get: Result = r | ||
} | ||
|
||
object IrrefutableIdentityExtractor { | ||
def unapply[A](a: A): IrrefutableNameBasedResult[A] = new IrrefutableNameBasedResult(a) | ||
} | ||
|
||
object IrrefutableSeqExtractor { | ||
def unapplySeq[A](a: A) = new IrrefutableNameBasedResult(List(a)) | ||
} | ||
|
||
def guardedNonExhaustive(x: Int) = x match { | ||
case IrrefutableIdentityExtractor(_) if false => "non-exhautive" | ||
} | ||
|
||
def guardedSeqNonExhaustive(x: Int) = x match { | ||
case IrrefutableSeqExtractor(_*) if false => "non-exhaustive" | ||
} | ||
|
||
//status quo: | ||
//should be in pos/t12240.scala but isn't exhaustive per | ||
//per https://github.com/scala/bug/issues/12252 | ||
def reported(v: Vector[String]) = v match { | ||
case Vector() => "empty" | ||
case Vector(_) => "one" | ||
case Vector(_, _, _*) => "scalac doesn't now this is exhaustive" | ||
} | ||
|
||
} |
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,65 @@ | ||
// scalac: -Xfatal-warnings -Xlint:strict-unsealed-patmat | ||
// | ||
|
||
object Test { | ||
|
||
//original reports | ||
|
||
def originalReported(v: Vector[String]) = v match { | ||
case Vector() => "empty" | ||
case Vector(_) => "one" | ||
case Vector(_*) => "this pattern is irrefutable" | ||
} | ||
|
||
def originalMinimized(v: Vector[String]) = v match { | ||
case Vector(_*) => "this pattern is irrefutable" | ||
} | ||
|
||
//broader applicability | ||
|
||
class IrrefutableNameBasedResult[Result](r: Result) { | ||
def isEmpty: false = false | ||
def get: Result = r | ||
} | ||
|
||
object IrrefutableIdentityExtractor { | ||
def unapply[A](a: A) = new IrrefutableNameBasedResult(a) | ||
} | ||
|
||
object IrrefutableSeqExtractor { | ||
def unapplySeq[A](a: A) = new IrrefutableNameBasedResult(List(a)) | ||
} | ||
|
||
def nameBasedPatternIsExhaustive(x: Int) = x match { | ||
case IrrefutableIdentityExtractor(_) => "exhaustive" | ||
} | ||
|
||
def nameBasedSeqIsExhaustive(x: Int) = x match { | ||
case IrrefutableSeqExtractor(_*) => "exhaustive" | ||
} | ||
|
||
//status quo: | ||
//should be in neg/t12240.scala but isn't exhaustive per | ||
//per https://github.com/scala/bug/issues/12252 | ||
|
||
def reported(v: Vector[String]) = v match { | ||
case Vector() => "empty" | ||
case Vector(_) => "one" | ||
case Vector(_, _, _*) => "this ought to be exhaustive" | ||
case Vector(_*) => "scalac doesn't know it's not exhaustive" | ||
} | ||
|
||
//status quo: | ||
//should be in neg/t12240.scala, but the unreachable code isn't reported | ||
//per https://github.com/scala/bug/issues/12251 | ||
def nameBasedPatternUnreachable(x: Int) = x match { | ||
case IrrefutableIdentityExtractor(_) => "exhaustive" | ||
case _ => "unreachable" | ||
} | ||
|
||
def nameBasedSeqUnreachable(x: Int) = x match { | ||
case IrrefutableSeqExtractor(_*) => "exhaustive" | ||
case _ => "unreachable" | ||
} | ||
|
||
} |
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