Skip to content

Commit

Permalink
Test custom conformance to 'Movable'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyouko-taiga committed Sep 17, 2023
1 parent 1bfdab8 commit f0299fd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Tests/EndToEndTests/TestCases/CustomMove.hylo
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)
}

0 comments on commit f0299fd

Please sign in to comment.