[vala/staging: 1/2] vala: Properly set CodeNode.error when reporting an error
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/2] vala: Properly set CodeNode.error when reporting an error
- Date: Sun, 16 Feb 2020 15:15:39 +0000 (UTC)
commit cfacb6554cf14b551c4c3a3b6ac835d13599df2e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Feb 10 10:42:41 2020 +0100
vala: Properly set CodeNode.error when reporting an error
vala/valaarraytype.vala | 3 +++
vala/valaassignment.vala | 2 ++
vala/valabinaryexpression.vala | 1 +
vala/valacastexpression.vala | 1 +
vala/valacreationmethod.vala | 1 +
vala/valadeclarationstatement.vala | 6 +++++-
vala/valadelegatetype.vala | 3 +++
vala/valadeletestatement.vala | 1 +
vala/valalocalvariable.vala | 1 +
vala/valamethod.vala | 10 ++++++++++
vala/valaobjecttype.vala | 2 ++
vala/valaparameter.vala | 5 +++++
vala/valapropertyaccessor.vala | 1 +
vala/valasignal.vala | 1 +
14 files changed, 37 insertions(+), 1 deletion(-)
---
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index bc5eb16d7..bb6dceb44 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -290,17 +290,20 @@ public class Vala.ArrayType : ReferenceType {
length.check (context);
if (length.value_type == null || !(length.value_type is IntegerType) ||
!length.is_constant ()) {
+ error = true;
Report.error (length.source_reference, "Expression of constant integer type
expected");
return false;
}
}
if (element_type is ArrayType) {
+ error = true;
Report.error (source_reference, "Stacked arrays are not supported");
return false;
} else if (element_type is DelegateType) {
var delegate_type = (DelegateType) element_type;
if (delegate_type.delegate_symbol.has_target) {
+ error = true;
Report.error (source_reference, "Delegates with target are not supported as
array element type");
return false;
}
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 9b5c7da5b..72f150314 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -283,9 +283,11 @@ public class Vala.Assignment : Expression {
&& context.analyzer.find_current_method () is CreationMethod) {
if (ma.inner.symbol_reference != context.analyzer.find_current_method
().this_parameter) {
// trying to set construct-only property in creation method
for foreign instance
+ error = true;
Report.error (ma.source_reference, "Property `%s' is
read-only".printf (prop.get_full_name ()));
return false;
} else {
+ error = true;
Report.error (ma.source_reference, "Cannot assign to
construct-only properties, use Object (property: value) constructor chain up");
return false;
}
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 705635033..60c911677 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -570,6 +570,7 @@ public class Vala.BinaryExpression : Expression {
right.target_type.nullable = false;
} else if (right.value_type is ArrayType) {
if (!left.value_type.compatible (((ArrayType)
right.value_type).element_type)) {
+ error = true;
Report.error (source_reference, "Cannot look for `%s' in `%s'".printf
(left.value_type.to_string (), right.value_type.to_string ()));
}
} else {
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index 1a1e6ad05..5dc5dc3e6 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -185,6 +185,7 @@ public class Vala.CastExpression : Expression {
// GVariant unboxing returns owned value
value_type.value_owned = true;
if (value_type.get_type_signature () == null) {
+ error = true;
Report.error (source_reference, "Casting of `GLib.Variant' to `%s' is not
supported".printf (value_type.to_qualified_string ()));
}
}
diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala
index 89db56abe..23d40fd39 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -176,6 +176,7 @@ public class Vala.CreationMethod : Method {
context.analyzer.current_symbol = old_symbol;
if (is_abstract || is_virtual || overrides) {
+ error = true;
Report.error (source_reference, "The creation method `%s' cannot be marked as
override, virtual, or abstract".printf (get_full_name ()));
return false;
}
diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala
index e10302413..459489ced 100644
--- a/vala/valadeclarationstatement.vala
+++ b/vala/valadeclarationstatement.vala
@@ -79,7 +79,11 @@ public class Vala.DeclarationStatement : CodeNode, Statement {
checked = true;
- declaration.check (context);
+ if (!declaration.check (context)) {
+ // ignore inner error
+ error = true;
+ return false;
+ }
return !error;
}
diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala
index 2c5efb911..4029f00af 100644
--- a/vala/valadelegatetype.vala
+++ b/vala/valadelegatetype.vala
@@ -102,15 +102,18 @@ public class Vala.DelegateType : CallableType {
var n_type_params = delegate_symbol.get_type_parameters ().size;
var n_type_args = get_type_arguments ().size;
if (n_type_args > 0 && n_type_args < n_type_params) {
+ error = true;
Report.error (source_reference, "too few type arguments");
return false;
} else if (n_type_args > 0 && n_type_args > n_type_params) {
+ error = true;
Report.error (source_reference, "too many type arguments");
return false;
}
foreach (DataType type in get_type_arguments ()) {
if (!type.check (context)) {
+ error = true;
return false;
}
}
diff --git a/vala/valadeletestatement.vala b/vala/valadeletestatement.vala
index ff3ff6891..eb1d92150 100644
--- a/vala/valadeletestatement.vala
+++ b/vala/valadeletestatement.vala
@@ -65,6 +65,7 @@ public class Vala.DeleteStatement : CodeNode, Statement {
if (!expression.check (context)) {
// if there was an error in the inner expression, skip this check
+ error = true;
return false;
}
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index fac3bc41c..a6a1a8842 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -163,6 +163,7 @@ public class Vala.LocalVariable : Variable {
if (variable_array_type != null && variable_array_type.inline_allocated
&& variable_array_type.length == null && !(initializer is ArrayCreationExpression)) {
+ error = true;
Report.error (source_reference, "Inline allocated array requires either a given
length or an initializer");
}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index f5b22131a..817888309 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -766,12 +766,16 @@ public class Vala.Method : Subroutine, Callable {
}
if (is_abstract && body != null) {
+ error = true;
Report.error (source_reference, "Abstract methods cannot have bodies");
} else if ((is_abstract || is_virtual) && is_extern) {
+ error = true;
Report.error (source_reference, "Extern methods cannot be abstract or virtual");
} else if (is_extern && body != null) {
+ error = true;
Report.error (source_reference, "Extern methods cannot have bodies");
} else if (!is_abstract && !external && source_type == SourceFileType.SOURCE && body == null)
{
+ error = true;
Report.error (source_reference, "Non-abstract, non-extern methods must have bodies");
}
@@ -849,6 +853,7 @@ public class Vala.Method : Subroutine, Callable {
// Add local variable to provide access to params arrays which will be constructed
out of the given va-args
if (param.params_array && body != null) {
if (params_array_var != null) {
+ error = true;
Report.error (param.source_reference, "Only one params-array
parameter is allowed");
continue;
}
@@ -859,9 +864,11 @@ public class Vala.Method : Subroutine, Callable {
type.element_type.value_owned = type.value_owned;
type.value_owned = true;
if (type.element_type.is_real_struct_type () && !type.element_type.nullable) {
+ error = true;
Report.error (param.source_reference, "Only nullable struct elements
are supported in params-array");
}
if (type.length != null) {
+ error = true;
Report.error (param.source_reference, "Passing length to params-array
is not supported yet");
}
params_array_var = new LocalVariable (type, param.name, null,
param.source_reference);
@@ -1049,14 +1056,17 @@ public class Vala.Method : Subroutine, Callable {
context.entry_point = this;
if (tree_can_fail) {
+ error = true;
Report.error (source_reference, "\"main\" method cannot throw errors");
}
if (is_inline) {
+ error = true;
Report.error (source_reference, "\"main\" method cannot be inline");
}
if (coroutine) {
+ error = true;
Report.error (source_reference, "\"main\" method cannot be async");
}
}
diff --git a/vala/valaobjecttype.vala b/vala/valaobjecttype.vala
index 154fa3872..53101926c 100644
--- a/vala/valaobjecttype.vala
+++ b/vala/valaobjecttype.vala
@@ -105,9 +105,11 @@ public class Vala.ObjectType : ReferenceType {
int n_type_args = get_type_arguments ().size;
if (n_type_args > 0 && n_type_args < object_type_symbol.get_type_parameters ().size) {
+ error = true;
Report.error (source_reference, "too few type arguments");
return false;
} else if (n_type_args > 0 && n_type_args > object_type_symbol.get_type_parameters ().size) {
+ error = true;
Report.error (source_reference, "too many type arguments");
return false;
}
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index 9c698458b..e447612d3 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -171,6 +171,7 @@ public class Vala.Parameter : Variable {
unowned ArrayType? variable_array_type = variable_type as ArrayType;
if (variable_array_type != null && variable_array_type.inline_allocated
&& !variable_array_type.fixed_length) {
+ error = true;
Report.error (source_reference, "Inline allocated array as parameter requires
to have fixed length");
}
}
@@ -181,12 +182,16 @@ public class Vala.Parameter : Variable {
&& direction != ParameterDirection.OUT) {
Report.warning (source_reference, "`null' incompatible with parameter type
`%s'".printf (variable_type.to_string ()));
} else if (!(initializer is NullLiteral) && direction == ParameterDirection.OUT) {
+ error = true;
Report.error (source_reference, "only `null' is allowed as default value for
out parameters");
} else if (direction == ParameterDirection.IN && !initializer.value_type.compatible
(variable_type)) {
+ error = true;
Report.error (initializer.source_reference, "Cannot convert from `%s' to
`%s'".printf (initializer.value_type.to_string (), variable_type.to_string ()));
} else if (direction == ParameterDirection.REF) {
+ error = true;
Report.error (source_reference, "default value not allowed for ref
parameter");
} else if (!initializer.is_accessible (this)) {
+ error = true;
Report.error (initializer.source_reference, "default value is less accessible
than method `%s'".printf (parent_symbol.get_full_name ()));
}
}
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index 18ea71466..bb718470f 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -170,6 +170,7 @@ public class Vala.PropertyAccessor : Subroutine {
if (source_reference == null || source_reference.file == null) {
// Hopefully good as is
} else if (!value_type.value_owned && source_reference.file.file_type
== SourceFileType.SOURCE) {
+ error = true;
Report.error (source_reference, "unowned return value for
getter of property `%s' not supported without accessor".printf (prop.get_full_name ()));
}
} else if (value_type.value_owned && (source_reference == null ||
source_reference.file == null)) {
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index f7b987994..a07a0f5d6 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -223,6 +223,7 @@ public class Vala.Signal : Symbol, Callable {
}
if (!is_virtual && body != null) {
+ error = true;
Report.error (source_reference, "Only virtual signals can have a default signal
handler body");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]