cgen: minor sum type fix
parent
ac0b235d3a
commit
66adf7a6b9
|
@ -1014,7 +1014,7 @@ fn (g mut Gen) match_expr(node ast.MatchExpr) {
|
||||||
match fe {
|
match fe {
|
||||||
ast.Type {
|
ast.Type {
|
||||||
it_type := g.typ(it.typ)
|
it_type := g.typ(it.typ)
|
||||||
g.writeln('$it_type* it = ($it_type*)tmp3.obj; // ST it')
|
g.writeln('$it_type* it = ($it_type*)${tmp}.obj; // ST it')
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
verror('match sum type')
|
verror('match sum type')
|
||||||
|
|
|
@ -41,11 +41,11 @@ void println(string s) {
|
||||||
void handle_expr(Expr e) {
|
void handle_expr(Expr e) {
|
||||||
Expr tmp1 = e;
|
Expr tmp1 = e;
|
||||||
if (tmp1.typ == _type_idx_IfExpr) {
|
if (tmp1.typ == _type_idx_IfExpr) {
|
||||||
IfExpr* it = (IfExpr*)tmp3.obj; // ST it
|
IfExpr* it = (IfExpr*)tmp1.obj; // ST it
|
||||||
println(tos3("if"));
|
println(tos3("if"));
|
||||||
}
|
}
|
||||||
else if (tmp1.typ == _type_idx_IntegerLiteral) {
|
else if (tmp1.typ == _type_idx_IntegerLiteral) {
|
||||||
IntegerLiteral* it = (IntegerLiteral*)tmp3.obj; // ST it
|
IntegerLiteral* it = (IntegerLiteral*)tmp1.obj; // ST it
|
||||||
println(tos3("integer"));
|
println(tos3("integer"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -62,5 +62,7 @@ int main() {
|
||||||
user.name = tos3("bob");
|
user.name = tos3("bob");
|
||||||
Option_int n = get_opt();
|
Option_int n = get_opt();
|
||||||
int a = /*opt*/(*(int*)n.data) + 3;
|
int a = /*opt*/(*(int*)n.data) + 3;
|
||||||
|
handle_expr((IfExpr){
|
||||||
|
0});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,4 +46,5 @@ fn main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
a := n + 3
|
a := n + 3
|
||||||
|
handle_expr(IfExpr{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1620,7 +1620,7 @@ fn (p mut Parser) match_expr() ast.MatchExpr {
|
||||||
}
|
}
|
||||||
p.scope.register_var(ast.Var{
|
p.scope.register_var(ast.Var{
|
||||||
name: 'it'
|
name: 'it'
|
||||||
typ: typ
|
typ: table.type_to_ptr(typ)
|
||||||
})
|
})
|
||||||
// TODO
|
// TODO
|
||||||
if p.tok.kind == .comma {
|
if p.tok.kind == .comma {
|
||||||
|
|
Loading…
Reference in New Issue