vala r1996 - in trunk: . vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1996 - in trunk: . vala
- Date: Fri, 7 Nov 2008 09:27:50 +0000 (UTC)
Author: juergbi
Date: Fri Nov 7 09:27:50 2008
New Revision: 1996
URL: http://svn.gnome.org/viewvc/vala?rev=1996&view=rev
Log:
2008-11-07 JÃrg Billeter <j bitron ch>
* vala/valareturnstatement.vala:
* vala/valasemanticanalyzer.vala:
Move return statement checking to ReturnStatement.check
Modified:
trunk/ChangeLog
trunk/vala/valareturnstatement.vala
trunk/vala/valasemanticanalyzer.vala
Modified: trunk/vala/valareturnstatement.vala
==============================================================================
--- trunk/vala/valareturnstatement.vala (original)
+++ trunk/vala/valareturnstatement.vala Fri Nov 7 09:27:50 2008
@@ -70,4 +70,77 @@
return_expression = new_node;
}
}
+
+ public override bool check (SemanticAnalyzer analyzer) {
+ if (checked) {
+ return !error;
+ }
+
+ checked = true;
+
+ if (return_expression != null) {
+ return_expression.target_type = analyzer.current_return_type;
+ }
+
+ accept_children (analyzer);
+
+ if (return_expression != null && return_expression.error) {
+ // ignore inner error
+ error = true;
+ return false;
+ }
+
+ if (analyzer.current_return_type == null) {
+ error = true;
+ Report.error (source_reference, "Return not allowed in this context");
+ return false;
+ }
+
+ if (return_expression == null) {
+ if (!(analyzer.current_return_type is VoidType)) {
+ error = true;
+ Report.error (source_reference, "Return without value in non-void function");
+ }
+ return !error;
+ }
+
+ if (analyzer.current_return_type is VoidType) {
+ Report.error (source_reference, "Return with value in void function");
+ return false;
+ }
+
+ if (return_expression.value_type == null) {
+ error = true;
+ Report.error (source_reference, "Invalid expression in return value");
+ return false;
+ }
+
+ if (!return_expression.value_type.compatible (analyzer.current_return_type)) {
+ error = true;
+ Report.error (source_reference, "Return: Cannot convert from `%s' to `%s'".printf (return_expression.value_type.to_string (), analyzer.current_return_type.to_string ()));
+ return false;
+ }
+
+ if (return_expression.value_type.is_disposable () &&
+ !analyzer.current_return_type.value_owned) {
+ error = true;
+ Report.error (source_reference, "Return value transfers ownership but method return type hasn't been declared to transfer ownership");
+ return false;
+ }
+
+ if (return_expression.symbol_reference is LocalVariable &&
+ return_expression.value_type.is_disposable () &&
+ !analyzer.current_return_type.value_owned) {
+ Report.warning (source_reference, "Local variable with strong reference used as return value and method return type hasn't been declared to transfer ownership");
+ }
+
+ if (analyzer.context.non_null && return_expression is NullLiteral
+ && !analyzer.current_return_type.nullable) {
+ Report.warning (source_reference, "`null' incompatible with return type `%s`".printf (analyzer.current_return_type.to_string ()));
+ }
+
+ add_error_types (return_expression.get_error_types ());
+
+ return !error;
+ }
}
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Fri Nov 7 09:27:50 2008
@@ -721,70 +721,7 @@
}
public override void visit_return_statement (ReturnStatement stmt) {
- if (stmt.return_expression != null) {
- stmt.return_expression.target_type = current_return_type;
- }
-
- stmt.accept_children (this);
-
- if (stmt.return_expression != null && stmt.return_expression.error) {
- // ignore inner error
- stmt.error = true;
- return;
- }
-
- 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) {
- if (current_return_type is VoidType) {
- return;
- } else {
- stmt.error = true;
- Report.error (stmt.source_reference, "Return without value in non-void function");
- return;
- }
- }
-
- if (current_return_type is VoidType) {
- Report.error (stmt.source_reference, "Return with value in void function");
- return;
- }
-
- if (stmt.return_expression.value_type == null) {
- stmt.error = true;
- Report.error (stmt.source_reference, "Invalid expression in return value");
- return;
- }
-
- if (!stmt.return_expression.value_type.compatible (current_return_type)) {
- stmt.error = true;
- Report.error (stmt.source_reference, "Return: Cannot convert from `%s' to `%s'".printf (stmt.return_expression.value_type.to_string (), current_return_type.to_string ()));
- return;
- }
-
- if (stmt.return_expression.value_type.is_disposable () &&
- !current_return_type.value_owned) {
- stmt.error = true;
- Report.error (stmt.source_reference, "Return value transfers ownership but method return type hasn't been declared to transfer ownership");
- return;
- }
-
- if (stmt.return_expression.symbol_reference is LocalVariable &&
- stmt.return_expression.value_type.is_disposable () &&
- !current_return_type.value_owned) {
- Report.warning (stmt.source_reference, "Local variable with strong reference used as return value and method return type hasn't been declared to transfer ownership");
- }
-
- if (context.non_null && stmt.return_expression is NullLiteral
- && !current_return_type.nullable) {
- Report.warning (stmt.source_reference, "`null' incompatible with return type `%s`".printf (current_return_type.to_string ()));
- }
-
- stmt.add_error_types (stmt.return_expression.get_error_types ());
+ stmt.check (this);
}
public override void visit_yield_statement (YieldStatement stmt) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]