[vala/staging] parser: Stricter mode for chained member initializer with --keep-going
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] parser: Stricter mode for chained member initializer with --keep-going
- Date: Sun, 21 Mar 2021 14:34:25 +0000 (UTC)
commit 101ac531c8894ada0be77a039452fdccdaed5d5d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Mar 21 10:46:16 2021 +0100
parser: Stricter mode for chained member initializer with --keep-going
Regression of 86bc23f2d7295ae3b2f5f79449d2c5a4a7a93a58
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1158
tests/Makefile.am | 2 ++
tests/parser-keep-going/member-initializer.vala | 22 ++++++++++++++++++++++
tests/parser-keep-going/tests-extra-environment.sh | 1 +
vala/valaparser.vala | 10 +++++-----
4 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c3083a2f3..3454623d2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -884,6 +884,7 @@ TESTS = \
parser/yield-return.vala \
parser/bug728574.vala \
parser/bug749576.vala \
+ parser-keep-going/member-initializer.vala \
resolver/class-base-cycle.test \
resolver/interface-prerequisite-cycle.test \
resolver/peek-inner-types-ambiguous.test \
@@ -1244,6 +1245,7 @@ endif
EXTRA_DIST = \
glib/tests-extra-environment.sh \
gtktemplate/tests-extra-environment.sh \
+ parser-keep-going/tests-extra-environment.sh \
linux/tests-extra-environment.sh \
nullability/tests-extra-environment.sh \
posix/tests-extra-environment.sh \
diff --git a/tests/parser-keep-going/member-initializer.vala b/tests/parser-keep-going/member-initializer.vala
new file mode 100644
index 000000000..4ab47a26d
--- /dev/null
+++ b/tests/parser-keep-going/member-initializer.vala
@@ -0,0 +1,22 @@
+struct Foo {
+ uint x;
+ int y;
+}
+
+class Bar {
+ public string s;
+}
+
+void main() {
+ var foo = Foo () {
+ x = (uint) 23,
+ y = 42
+ };
+ assert (foo.x == 23U);
+ assert (foo.y == 42);
+
+ var bar = new Bar () {
+ s = "bar"
+ };
+ assert (bar.s == "bar");
+}
diff --git a/tests/parser-keep-going/tests-extra-environment.sh
b/tests/parser-keep-going/tests-extra-environment.sh
new file mode 100644
index 000000000..2c64eea67
--- /dev/null
+++ b/tests/parser-keep-going/tests-extra-environment.sh
@@ -0,0 +1 @@
+VALAFLAGS="--keep-going"
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 7236d5c7b..4cbe72358 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -302,11 +302,11 @@ public class Vala.Parser : CodeVisitor {
}
}
- string parse_identifier () throws ParseError {
+ string parse_identifier (bool required = false) throws ParseError {
try {
skip_identifier ();
} catch (ParseError e) {
- if (context.keep_going) {
+ if (!required && context.keep_going) {
report_parse_error (e);
prev ();
return get_location_string ();
@@ -1060,16 +1060,16 @@ public class Vala.Parser : CodeVisitor {
return list;
}
- MemberInitializer parse_member_initializer () throws ParseError {
+ MemberInitializer parse_member_initializer (bool chained = false) throws ParseError {
var begin = get_location ();
- string id = parse_identifier ();
+ string id = parse_identifier (chained);
expect (TokenType.ASSIGN);
var inner = get_location ();
Expression expr;
try {
// chained member initializer
- expr = parse_member_initializer ();
+ expr = parse_member_initializer (true);
} catch {
rollback (inner);
expr = parse_expression ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]