[vala/staging] vala: Add local-variables to current scope regardless its error state
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Add local-variables to current scope regardless its error state
- Date: Sat, 22 Feb 2020 15:02:43 +0000 (UTC)
commit dea6e30ad81e6da4ae6777365827956c4d8ab46f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Feb 22 16:00:22 2020 +0100
vala: Add local-variables to current scope regardless its error state
This avoids subsequent errors which are not useful to report when the user
actually defined it.
vala/valalocalvariable.vala | 17 +++++++++--------
vala/valamemberaccess.vala | 4 ++++
2 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index ec7b0da87..2d6f7188b 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -100,11 +100,8 @@ public class Vala.LocalVariable : Variable {
if (variable_type is VoidType) {
error = true;
Report.error (source_reference, "'void' not supported as variable type");
- return false;
- }
- if (!variable_type.check (context)) {
+ } else if (!variable_type.check (context)) {
error = true;
- return false;
}
if (!external_package) {
context.analyzer.check_type (variable_type);
@@ -115,7 +112,7 @@ public class Vala.LocalVariable : Variable {
bool is_initializer_list = false;
int initializer_size = -1;
- if (initializer != null) {
+ if (initializer != null && !error) {
initializer.target_type = variable_type;
if (initializer is InitializerList) {
@@ -125,10 +122,16 @@ public class Vala.LocalVariable : Variable {
if (!initializer.check (context)) {
error = true;
- return false;
}
}
+ // local variables are defined even on errors
+ context.analyzer.current_symbol.scope.add (name, this);
+
+ if (error) {
+ return false;
+ }
+
if (variable_type is VarType) {
/* var type */
@@ -223,8 +226,6 @@ public class Vala.LocalVariable : Variable {
}
}
- context.analyzer.current_symbol.scope.add (name, this);
-
// current_symbol is a Method if this is the `result'
// variable used for postconditions
unowned Block? block = context.analyzer.current_symbol as Block;
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index a0dc84d62..b8d5d1252 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -506,6 +506,10 @@ public class Vala.MemberAccess : Expression {
Report.error (source_reference, "The name `%s' does not exist in the context of
`%s'%s".printf (member_name, base_type_name, base_type_package));
return false;
+ } else if (symbol_reference.error) {
+ //ignore previous error
+ error = true;
+ return false;
}
unowned Symbol? member = symbol_reference;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]