Panther Search Documentation Tutorials Downloads Devlog Source Code

When Conditionals

When conditionals are conditionals that are evaluated at compile-time. The condition may be any comptime value. The bodies may hold 0 or more statements (this includes things like members of structs). Any statements in a when conditional block that is not taken will not exist in semantic analysis or any further compiler stage.

Example

Panther
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
def math = @import("math"); when(math.PI < 2.0){ // since this branch is not taken, this function won't exist func sum = (lhs: Int, rhs: Int) #pub -> Int { return lhs + rhs; } }else when(true){ // this branch is taken, so this version of `Integer` is used alias Integer = I64; }else when(false){ // empty... }else{ // since this branch is not taken, no error is emitted const foo: Int = true; // since this branch is not taken, this version of `Integer` is not used alias Integer = I32; } // `num` is of type I64 const num: Integer = 14;