navid/haze / a23ce05222314a23cbee0f97752ef1a1aa9c94af4a3ea4b068cde58edf373fc1 / samples/baseline_2.5/casting_contracts.hz
casting_contracts.hz
← samples/baseline_2.5 · 328 bytes · raw · download
// Casts inside contracts and expression-bodied functions.
contract NonNegative(n i16) {
pre cast[i32](n) >= 0
}
fn half(n i16) i16
: NonNegative(n)
: post r => cast[i32](r) * 2 == cast[i32](n)
=> trunc[i16](cast[i32](n) / 2)
fn main() {
var n i16 = 100
print(half(n))
print(cast[i32](half(n)))
}