From: Rico Tzschichholz Date: Mon, 9 Nov 2020 14:06:20 +0000 (+0100) Subject: vala: Additionally look for "length" property for "foreach with index" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21028c0f59b72e4538c33a7b9618e71474a665db;p=thirdparty%2Fvala.git vala: Additionally look for "length" property for "foreach with index" --- diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala index 2c81b202a..493540f20 100644 --- a/vala/valaforeachstatement.vala +++ b/vala/valaforeachstatement.vala @@ -206,6 +206,9 @@ public class Vala.ForeachStatement : Block { } var size_property = collection_type.get_member ("size") as Property; if (size_property == null) { + size_property = collection_type.get_member ("length") as Property; + } + if (size_property == null || !(size_property.property_type is IntegerType)) { return false; } @@ -214,7 +217,7 @@ public class Vala.ForeachStatement : Block { list_type.value_owned = false; } add_statement (new DeclarationStatement (new LocalVariable (list_type, "_%s_list".printf (variable_name), collection, source_reference), source_reference)); - add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_size".printf (variable_name), new MemberAccess (new MemberAccess.simple ("_%s_list".printf (variable_name), source_reference), "size", source_reference), source_reference), source_reference)); + add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_size".printf (variable_name), new MemberAccess (new MemberAccess.simple ("_%s_list".printf (variable_name), source_reference), size_property.name, source_reference), source_reference), source_reference)); add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_index".printf (variable_name), new UnaryExpression (UnaryOperator.MINUS, new IntegerLiteral ("1", source_reference), source_reference), source_reference), source_reference)); var next = new UnaryExpression (UnaryOperator.INCREMENT, new MemberAccess.simple ("_%s_index".printf (variable_name), source_reference), source_reference); var conditional = new BinaryExpression (BinaryOperator.LESS_THAN, next, new MemberAccess.simple ("_%s_size".printf (variable_name), source_reference), source_reference);