-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for redundant type checks for pattern matching
- Loading branch information
1 parent
5cf8cde
commit 4e34923
Showing
17 changed files
with
263 additions
and
47 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns1.dotty.check
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,3 @@ | ||
[ Error ] InvalidTypedPatterns1.scala:13:47: Unsupported pattern: _:B | ||
case MyOtherClass(s1: A, MyOtherClass(s2: B, moc2: MyOtherClass[A, B])) => s1 // s2: B is invalid | ||
^ |
15 changes: 15 additions & 0 deletions
15
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns1.scala
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 @@ | ||
import stainless.lang._ | ||
|
||
object InvalidTypedPatterns1 { | ||
|
||
case class MyOtherClass[S, T](s1: S, s2: S, t: T) | ||
|
||
object MyOtherClass { | ||
def unapply[S, T](moc: MyOtherClass[S, T]): Option[(S, MyOtherClass[S, T])] = Some((moc.s1, moc)) | ||
} | ||
|
||
|
||
def test[A, B](moc: MyOtherClass[A, B]): A = moc match { | ||
case MyOtherClass(s1: A, MyOtherClass(s2: B, moc2: MyOtherClass[A, B])) => s1 // s2: B is invalid | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns1.scalac.check
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,3 @@ | ||
[ Error ] InvalidTypedPatterns1.scala:13:45: Unsupported pattern: (_: B) | ||
case MyOtherClass(s1: A, MyOtherClass(s2: B, moc2: MyOtherClass[A, B])) => s1 // s2: B is invalid | ||
^^^ |
1 change: 1 addition & 0 deletions
1
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns2.dotty.check
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 @@ | ||
[ Error ] Stainless does not support type B & A |
5 changes: 5 additions & 0 deletions
5
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns2.scala
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,5 @@ | ||
object InvalidTypedPatterns2 { | ||
def test[A, B](a: A, b: B): Unit = { | ||
val (aa1: A, bb: A) = (a, b) // bb: A is invalid | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns2.scalac.check
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,3 @@ | ||
[ Error ] InvalidTypedPatterns2.scala:3:20: Unsupported pattern: (_: A) | ||
val (aa1: A, bb: A) = (a, b) // bb: A is invalid | ||
^^^ |
3 changes: 3 additions & 0 deletions
3
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns3.dotty.check
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,3 @@ | ||
[ Error ] InvalidTypedPatterns3.scala:5:29: Unsupported pattern: _:B | ||
case MyClass(a1: A, a2: B, b: B) => a1 // a2: B is invalid | ||
^ |
7 changes: 7 additions & 0 deletions
7
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns3.scala
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,7 @@ | ||
object InvalidTypedPatterns3 { | ||
case class MyClass[S, T](s1: S, s2: S, t: T) | ||
|
||
def test[A, B](mc: MyClass[A, B]): A = mc match { | ||
case MyClass(a1: A, a2: B, b: B) => a1 // a2: B is invalid | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns3.scalac.check
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,3 @@ | ||
[ Error ] InvalidTypedPatterns3.scala:5:27: Unsupported pattern: (_: B) | ||
case MyClass(a1: A, a2: B, b: B) => a1 // a2: B is invalid | ||
^^^ |
3 changes: 3 additions & 0 deletions
3
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns4.dotty.check
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,3 @@ | ||
[ Error ] InvalidTypedPatterns4.scala:5:31: Unsupported pattern: _:String | ||
case MyClass(a1: Int, a2: String, b: String) => a1 // a2: String is invalid | ||
^^^^^^ |
7 changes: 7 additions & 0 deletions
7
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns4.scala
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,7 @@ | ||
object InvalidTypedPatterns4 { | ||
case class MyClass[S, T](s1: S, s2: S, t: T) | ||
|
||
def test5(mc: MyClass[Int, String]): Int = mc match { | ||
case MyClass(a1: Int, a2: String, b: String) => a1 // a2: String is invalid | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
frontends/benchmarks/extraction/invalid/InvalidTypedPatterns4.scalac.check
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,5 @@ | ||
[ Error ] InvalidTypedPatterns4.scala:5:31: scrutinee is incompatible with pattern type; | ||
[ Error ] found : String | ||
[ Error ] required: Int | ||
case MyClass(a1: Int, a2: String, b: String) => a1 // a2: String is invalid | ||
^ |
38 changes: 38 additions & 0 deletions
38
frontends/benchmarks/extraction/valid/StateMonadTypeRefIssue.scala
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 @@ | ||
object StateMonad { | ||
|
||
case class St[A,S](fun: S => (A,S)) { | ||
def ^=(that: St[A,S])(implicit anyS: S): St[A,S] = { | ||
assert(this.fun(anyS) == that.fun(anyS)) | ||
that | ||
} | ||
|
||
def qed: Unit = | ||
??? | ||
|
||
def flatMap[B](f: A => St[B,S]): St[B,S] = | ||
St[B,S] { | ||
s0 => | ||
val (a,s1) = fun(s0) | ||
f(a).fun(s1) | ||
} | ||
|
||
def unit[A,S](a: A) = | ||
St[A,S] { | ||
(s:S) => (a,s) | ||
} | ||
|
||
def leftUnit[A,S,B](a: A, f: A => St[B,S])(implicit anyS: S): Unit = { | ||
(unit(a).flatMap(f) ^= | ||
St((s:S) => (a:A,s:S)).flatMap(f) ^= | ||
St { (s0:S) => | ||
val (a1:A,s1:S) = ((s:S) => (a,s))(s0) | ||
f(a1).fun(s1) } ^= | ||
St { s0 => | ||
val (a1:A,s1:S) = (a,s0) | ||
f(a1).fun(s1) } ^= | ||
St(s0 => f(a).fun(s0)) ^= | ||
f(a)) | ||
.qed | ||
}.ensuring(_ => unit(a).flatMap(f) == f(a)) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
frontends/benchmarks/verification/valid/RedundantlyTypedPatterns.scala
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,41 @@ | ||
import stainless.lang._ | ||
|
||
object RedundantlyTypedPatterns { | ||
|
||
case class MyClass[S, T](s1: S, s2: S, t: T) | ||
|
||
case class MyOtherClass[S, T](s1: S, s2: S, t: T) | ||
|
||
case class YetAnotherClass(i1: Int, s: String, i2: Int) | ||
|
||
object MyOtherClass { | ||
def unapply[S, T](moc: MyOtherClass[S, T]): Option[(S, MyOtherClass[S, T])] = Some((moc.s1, moc)) | ||
} | ||
|
||
|
||
def test1[A, B](moc: MyOtherClass[A, B]): A = moc match { | ||
case MyOtherClass(s1: A, MyOtherClass(s2: A, moc2: MyOtherClass[A, B])) => s1 | ||
} | ||
|
||
def test2[A, B](moc: MyOtherClass[A, B]): A = moc match { | ||
case MyOtherClass(s1, MyOtherClass(s2, moc2)) => s1 | ||
} | ||
|
||
def test3[A, B](a: A, b: B): Unit = { | ||
val (aa1: A, bb: B) = (a, b) | ||
val (aa2: A, ab1: (A, B)) = (a, (a, b)) | ||
val (ab2: (A, B), aa3: A) = ((a, b), a) | ||
} | ||
|
||
def test4[A, B](mc: MyClass[A, B]): A = mc match { | ||
case MyClass(a1: A, a2: A, b: B) => a1 | ||
} | ||
|
||
def test5(mc: MyClass[Int, String]): Int = mc match { | ||
case MyClass(a1: Int, a2: Int, b: String) => a1 | ||
} | ||
|
||
def test6(yac: YetAnotherClass): Int = yac match { | ||
case YetAnotherClass(a1: Int, a2: String, a3: Int) => a1 | ||
} | ||
} |
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
Oops, something went wrong.