From 32b9ec5ae909870f268e31788d04099015af6fdb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Fri, 14 Aug 2020 12:43:31 +0200 Subject: [PATCH] :art: foreach --- ast | 2 +- examples/auto.gw | 2 +- src/parse/check.c | 4 +++- tests/error/auto_not_array.gw | 2 +- tests/error/null_auto.gw | 2 +- tests/range/range_char.gw | 2 +- tests/range/range_int.gw | 2 +- tests/tree/auto_array.gw | 2 +- tests/tree/auto_fun.gw | 2 +- tests/tree/auto_ptr.gw | 2 +- tests/tree/cpy_ast.gw | 2 +- tests/tree/set_obj.gw | 2 +- tests/tree/typedef_auto_loop.gw | 2 +- 13 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ast b/ast index a900e6c5..793836da 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit a900e6c56c8d1e6d89221df0401dc27150218b0d +Subproject commit 793836da41b41f3a4ff1e968f6849275d0224ba9 diff --git a/examples/auto.gw b/examples/auto.gw index 13a427c0..bb91217b 100644 --- a/examples/auto.gw +++ b/examples/auto.gw @@ -1,3 +1,3 @@ Object i[4]; -for(auto a: i) +foreach(a: i) <<< a >>>; diff --git a/src/parse/check.c b/src/parse/check.c index bbeee460..c6973072 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -831,8 +831,10 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary* bin) { CHECK_OO(check_exp(env, bin->lhs)) const m_bool is_auto = bin->rhs->exp_type == ae_exp_decl && bin->rhs->d.exp_decl.type == env->gwion->type[et_auto]; if(is_auto) - bin->rhs->info->type = bin->rhs->d.exp_decl.type = bin->lhs->info->type; + bin->rhs->d.exp_decl.type = bin->lhs->info->type; CHECK_OO(check_exp(env, bin->rhs)) + if(is_auto) + bin->rhs->info->type = bin->lhs->info->type; struct Op_Import opi = { .op=bin->op, .lhs=bin->lhs->info->type, .rhs=bin->rhs->info->type, .data=(uintptr_t)bin, .pos=exp_self(bin)->pos, .op_type=op_binary }; const Type ret = op_check(env, &opi); diff --git a/tests/error/auto_not_array.gw b/tests/error/auto_not_array.gw index 95170ee8..6a364207 100644 --- a/tests/error/auto_not_array.gw +++ b/tests/error/auto_not_array.gw @@ -1,4 +1,4 @@ #! [contains] not allowed in auto loop Object i; -for(auto a: i) +foreach(a: i) <<< a >>>; diff --git a/tests/error/null_auto.gw b/tests/error/null_auto.gw index 673ee992..08638ea7 100644 --- a/tests/error/null_auto.gw +++ b/tests/error/null_auto.gw @@ -1,4 +1,4 @@ #! [contains] NullPtrException int i[]; -for(auto a : i) +foreach(a : i) <<< a >>>; diff --git a/tests/range/range_char.gw b/tests/range/range_char.gw index 39c40da4..7be54285 100644 --- a/tests/range/range_char.gw +++ b/tests/range/range_char.gw @@ -1,3 +1,3 @@ #! [contains] b -for(auto a : [ 'a' : 'c' ]) +foreach(a : [ 'a' : 'c' ]) <<< a >>>; diff --git a/tests/range/range_int.gw b/tests/range/range_int.gw index 7aaa7a38..870d1fd1 100644 --- a/tests/range/range_int.gw +++ b/tests/range/range_int.gw @@ -1,3 +1,3 @@ #! [contains] \-5 -for(auto a : [ -1 : -6 ]) +foreach(a : [ -1 : -6 ]) <<< a >>>; diff --git a/tests/tree/auto_array.gw b/tests/tree/auto_array.gw index f4d33e6e..0306b9b0 100644 --- a/tests/tree/auto_array.gw +++ b/tests/tree/auto_array.gw @@ -1,4 +1,4 @@ int i[2][2]; -for(auto ref a : i) +foreach(ref a : i) <<< a >>>; <<< i >>>; diff --git a/tests/tree/auto_fun.gw b/tests/tree/auto_fun.gw index 30eaf3d3..12d1d89b 100644 --- a/tests/tree/auto_fun.gw +++ b/tests/tree/auto_fun.gw @@ -4,6 +4,6 @@ class C { C i[2]; -for(auto ref a : i) +foreach(ref a : i) <<< a >>>; diff --git a/tests/tree/auto_ptr.gw b/tests/tree/auto_ptr.gw index 10af68c8..b8fe29ef 100644 --- a/tests/tree/auto_ptr.gw +++ b/tests/tree/auto_ptr.gw @@ -1,5 +1,5 @@ <~int~>Ptr ptr; int i[4]; -for(auto ref a : i) +foreach(ref a : i) <<< *a >>>; <<< ptr >>>; diff --git a/tests/tree/cpy_ast.gw b/tests/tree/cpy_ast.gw index c0d2c2f9..1266d89d 100644 --- a/tests/tree/cpy_ast.gw +++ b/tests/tree/cpy_ast.gw @@ -15,7 +15,7 @@ class <~A~>C { for(int; i < 1; ++i); int array[2]; array[0]; - for(auto a : array); + foreach(a : array); repeat(1); match i,2 { case 12 when 0:; diff --git a/tests/tree/set_obj.gw b/tests/tree/set_obj.gw index 043de2bc..30e835ce 100644 --- a/tests/tree/set_obj.gw +++ b/tests/tree/set_obj.gw @@ -1,4 +1,4 @@ typedef int[2]Type; Type nonnull type; <<>>; -for(auto ref a : type); +foreach(ref a : type); diff --git a/tests/tree/typedef_auto_loop.gw b/tests/tree/typedef_auto_loop.gw index cadca626..37e58a13 100644 --- a/tests/tree/typedef_auto_loop.gw +++ b/tests/tree/typedef_auto_loop.gw @@ -1,3 +1,3 @@ typedef int[2] Type; Type type; -for(auto a : type); +foreach(a : type); -- 2.43.0