mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add compile time ternary $val ??? <expr> : <expr>.
This commit is contained in:
25
test/test_suite/statements/ct_ternary.c3t
Normal file
25
test/test_suite/statements/ct_ternary.c3t
Normal file
@@ -0,0 +1,25 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
import std;
|
||||
|
||||
fn int main()
|
||||
{
|
||||
int aa = false ??? 1 + a : 2;
|
||||
int x = 42;
|
||||
int bb = true ??? x : 1 + a;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%aa = alloca i32, align 4
|
||||
%x = alloca i32, align 4
|
||||
%bb = alloca i32, align 4
|
||||
store i32 2, ptr %aa, align 4
|
||||
store i32 42, ptr %x, align 4
|
||||
%0 = load i32, ptr %x, align 4
|
||||
store i32 %0, ptr %bb, align 4
|
||||
ret i32 0
|
||||
}
|
||||
@@ -2,8 +2,8 @@ module std::core::values @test;
|
||||
|
||||
fn void test_select()
|
||||
{
|
||||
const int X = @select(true, 1, "Hello");
|
||||
const String Y = @select(false, 1, "Hello");
|
||||
const int X = true ??? 1 : "Hello";
|
||||
const String Y = false ??? 1 : "Hello";
|
||||
test::eq(X, 1);
|
||||
test::eq(Y, "Hello");
|
||||
}
|
||||
Reference in New Issue
Block a user