navid/haze / cb1bac46fbd9fca0f0e2a401590740b0840b47821983a25743fc29c1572577d9 / 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)))
}