Commit c6fa0202 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

check whether specified collection is iterable in foreach statements,

2007-04-30  Jürg Billeter  <j@bitron.ch>

	* vala/valasemanticanalyzer.vala: check whether specified collection is
	  iterable in foreach statements, fixes bug 434514

svn path=/trunk/; revision=294
parent 06ef9db4
2007-04-30 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: check whether specified collection is
iterable in foreach statements, fixes bug 434514
2007-04-30 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: allow any integer type as index in an
......
......@@ -48,6 +48,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
TypeReference type_type;
DataType pointer_type;
DataType initially_unowned_type;
DataType glist_type;
DataType gslist_type;
private int next_lambda_id = 0;
......@@ -84,6 +86,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
type_type = new TypeReference ();
type_type.data_type = (DataType) glib_ns.lookup ("Type").node;
glist_type = (DataType) glib_ns.lookup ("List").node;
gslist_type = (DataType) glib_ns.lookup ("SList").node;
}
current_symbol = root_symbol;
......@@ -780,13 +785,24 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
stmt.body.symbol.add (stmt.variable_name, stmt.variable_declarator.symbol);
}
public override void visit_end_foreach_statement (ForeachStatement! stmt) {
var collection_type = stmt.collection.static_type.data_type;
if (!(collection_type is Array || collection_type == glist_type || collection_type == gslist_type)) {
stmt.error = true;
Report.error (stmt.source_reference, "Collection not iterable");
return;
}
}
public override void visit_end_return_statement (ReturnStatement! stmt) {
if (current_return_type == null) {
stmt.error = true;
Report.error (stmt.source_reference, "Return not allowed in this context");
return;
}
if (stmt.return_expression == null && current_return_type.data_type != null) {
stmt.error = true;
Report.error (stmt.source_reference, "Return without value in non-void function");
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment