1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sum types

This commit is contained in:
Alexander Medvednikov
2019-12-23 00:31:28 +03:00
parent d2c3c66ba4
commit 7ab993c218
4 changed files with 126 additions and 11 deletions

View File

@@ -54,3 +54,48 @@ fn test_nums() {
d := Foo.d
assert d == -10
}
enum Expr {
BoolExpr(bool)
IntExpr(int)
//FloatExpr(int)
}
fn get_expr() Expr {
return Expr.IntExpr(10)
}
fn test_typed_enum() {
i := Expr.IntExpr(10)
expr := Expr.BoolExpr(true)
//println(i)
//if i == expr {
//}
println('done')
// expr = i
/*
match expr {
IntExpr(n) { println('INT $n') }
BoolExpr(b) { println('BOOL $b') }
}
*/
}
/*
fn test_typed_enum() {
Expr i = { .obj = 10, .typ = IntExpr_type };
Expr expr = { .obj = true, .typ = BoolExpr_type };
// val = expr;
if (expr.typ == IntExpr_type) {
int n = (int)expr.obj;
println('INT $n');
}
else if (expr.typ == BoolExpr_type) {
int b = (bool)expr.obj;
println('BOOL $b');
}
}
*/