]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Report error when field initializers may throw errors
authorJürg Billeter <j@bitron.ch>
Sun, 13 Dec 2009 17:08:07 +0000 (18:08 +0100)
committerJürg Billeter <j@bitron.ch>
Sun, 13 Dec 2009 17:08:07 +0000 (18:08 +0100)
vala/valamethodcall.vala
vala/valaobjectcreationexpression.vala

index ab4702432cca1612c4bda27d8f03733a78099fe3..8ac74a9a4a58f42072bff4678b5c7b6d7d342ca0 100644 (file)
@@ -499,6 +499,9 @@ public class Vala.MethodCall : Expression {
                if (may_throw) {
                        if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
                                // simple statements, no side effects after method call
+                       } else if (!(analyzer.current_symbol is Block)) {
+                               // can't handle errors in field initializers
+                               Report.error (source_reference, "Field initializers must not throw errors");
                        } else {
                                // store parent_node as we need to replace the expression in the old parent node later on
                                var old_parent_node = parent_node;
index 4a038ce3da3e8248c060f3439897caa2897f0cd3..f0c910822a3d2312cdfdefd508d797774545c534 100644 (file)
@@ -386,6 +386,9 @@ public class Vala.ObjectCreationExpression : Expression {
                if (may_throw) {
                        if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
                                // simple statements, no side effects after method call
+                       } else if (!(analyzer.current_symbol is Block)) {
+                               // can't handle errors in field initializers
+                               Report.error (source_reference, "Field initializers must not throw errors");
                        } else {
                                // store parent_node as we need to replace the expression in the old parent node later on
                                var old_parent_node = parent_node;