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 #9343 from martijnhoekstra/namebasedirrefutable
- Loading branch information
Showing
21 changed files
with
311 additions
and
56 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
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-exhaustive" | ||
} | ||
|
||
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 know that 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
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 was already 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// scalac: -Xfatal-warnings -Xlint:strict-unsealed-patmat | ||
// | ||
|
||
object Test { | ||
sealed trait Foo | ||
final class Bar extends Foo | ||
|
||
object Bar { | ||
def unapply(o: Bar): true = true | ||
} | ||
|
||
def f(foo: Foo) = foo match { | ||
case Bar() => println("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,36 @@ | ||
[[syntax trees at end of patmat]] // newSource1.scala | ||
package <empty> { | ||
object A extends scala.AnyRef { | ||
def <init>(): A.type = { | ||
A.super.<init>(); | ||
() | ||
}; | ||
def unapplySeq(a: Int): Wrap = new Wrap(a) | ||
}; | ||
class T extends scala.AnyRef { | ||
def <init>(): T = { | ||
T.super.<init>(); | ||
() | ||
}; | ||
def t: Any = { | ||
case <synthetic> val x1: Int(2) = 2; | ||
case5(){ | ||
<synthetic> val o7: Wrap = A.unapplySeq(x1); | ||
if (o7.isEmpty.unary_!) | ||
{ | ||
val xs: Seq[Int] = o7.get.toSeq; | ||
matchEnd4(xs) | ||
} | ||
else | ||
case6() | ||
}; | ||
case6(){ | ||
matchEnd4("other") | ||
}; | ||
matchEnd4(x: Any){ | ||
x | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.