-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test custom conformance to 'Movable'
- Loading branch information
1 parent
1bfdab8
commit f0299fd
Showing
1 changed file
with
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//- compileAndRun expecting: success | ||
|
||
type A: Deinitializable { | ||
var witness: Int | ||
public var x: Int | ||
public init(x: sink Int) { | ||
&self.x = x | ||
&self.witness = 0 | ||
} | ||
} | ||
|
||
conformance A: Movable { | ||
public fun take_value(from source: sink Self) -> {self: Self, Void} { | ||
set { | ||
&self.x = source.x | ||
&self.witness = 0 | ||
} | ||
inout { | ||
&self.x = source.x | ||
&self.witness += 1 | ||
} | ||
} | ||
} | ||
|
||
public fun main() { | ||
var s = A(x: 1) | ||
&s = A(x: 2) | ||
&s = A(x: 2) | ||
|
||
precondition(s.x == 2) | ||
precondition(s.witness == 2) | ||
} |