-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test with mutable pattern match.
- Loading branch information
1 parent
6dda86f
commit d3e243c
Showing
2 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
extern crate stainless; | ||
|
||
struct S<T>(T); | ||
struct Container<T> { | ||
s: S<T>, | ||
} | ||
|
||
pub fn main() { | ||
let mut c = Container { s: S("hello") }; | ||
|
||
match &mut c.s { | ||
S(v) if *v == "hello" => *v = "world", | ||
_ => {} | ||
}; | ||
|
||
assert!(c.s.0 == "world") | ||
} | ||
|
||
/* | ||
Desired Scala translation: | ||
import stainless.annotation._ | ||
object Fields { | ||
case class S[@mutable T](_0: MutCell[T]) | ||
case class MutCell[@mutable T](var value: T) | ||
case class Container[@mutable T](s: MutCell[S[T]]) | ||
def main: Unit = { | ||
var c: Container[String] = Container(MutCell(S(MutCell("hello")))) | ||
(c.s match { | ||
case MutCell(S(v)) if v.value == "hello" => | ||
v.value = "world" | ||
case _ => | ||
() | ||
}) | ||
assert(c.s.value._0.value == "world") | ||
} | ||
} | ||
*/ |