-
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.
Fix MatchError in EffectsAnalyzer (#1492)
- Loading branch information
1 parent
2e20a3b
commit 536d418
Showing
2 changed files
with
36 additions
and
1 deletion.
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
35 changes: 35 additions & 0 deletions
35
frontends/benchmarks/imperative/valid/MutableArrayFieldInTrait.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,35 @@ | ||
import stainless.annotation._ | ||
import stainless.lang._ | ||
import StaticChecks._ | ||
|
||
object MutableArrayFieldInTrait { | ||
case class Buffer(arr: Array[Byte]) | ||
|
||
@mutable | ||
trait MyTrait { | ||
val buf: Buffer | ||
|
||
final def modify: Unit = { | ||
if (buf.arr.length >= 10) buf.arr(0) = 1 | ||
} | ||
} | ||
case class MyClass(buf: Buffer) extends MyTrait | ||
|
||
def modify(buf: Buffer, i: Int): Unit = { | ||
require(0 <= i && i < buf.arr.length) | ||
buf.arr(i) = 42 | ||
} | ||
|
||
def test(mt: MyTrait, i: Int, j: Int, k: Int): Unit = { | ||
require(0 <= i && i < mt.buf.arr.length) | ||
require(0 <= j && j < mt.buf.arr.length) | ||
require(0 <= k && k < mt.buf.arr.length) | ||
require(i != j && j != k && i != k) | ||
val oldi = mt.buf.arr(i) | ||
modify(mt.buf, j) | ||
mt.buf.arr(k) = 24 | ||
assert(mt.buf.arr(i) == oldi) | ||
assert(mt.buf.arr(j) == 42) | ||
assert(mt.buf.arr(k) == 24) | ||
} | ||
} |