Index: vala/valasemanticanalyzer.vala =================================================================== --- vala/valasemanticanalyzer.vala (revision 602) +++ vala/valasemanticanalyzer.vala (working copy) @@ -870,6 +870,25 @@ stmt.variable_declarator.active = true; } + private bool has_method (DataType data_type, string! method_name) + { + if (data_type is Interface) { + Interface iface = (Interface) data_type; + foreach (Method m in iface.get_methods ()) { + if (m.parameters.size != 0) + continue; + if (m.get_full_name () == method_name) { + if (m.return_type is iterator_type) { + found = true; + break; + } + } + } + } else if (data_type is Class) { + // TODO + } + } + public override void visit_end_foreach_statement (ForeachStatement! stmt) { if (stmt.collection.error) { // ignore inner error @@ -886,7 +905,7 @@ stmt.collection_variable_declarator.active = true; var collection_type = stmt.collection.static_type.data_type; - if (iterable_type != null && collection_type.is_subtype_of (iterable_type)) { + if ((iterable_type != null && collection_type.is_subtype_of (iterable_type)) || has_method (collection_type, "get_iterator")) { stmt.iterator_variable_declarator = new VariableDeclarator ("%s_it".printf (stmt.variable_name)); stmt.iterator_variable_declarator.type_reference = new TypeReference (); stmt.iterator_variable_declarator.type_reference.data_type = iterator_type;