[vala/0.46] genie: Fix parser's inner state when a struct is declared after a class
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.46] genie: Fix parser's inner state when a struct is declared after a class
- Date: Wed, 5 Feb 2020 10:03:21 +0000 (UTC)
commit 5dad77dcc6090dbf89ecd0ca7ebe4948abb82f32
Author: Jeremy Philippe <jeremy philippe gmail com>
Date: Sat Dec 21 20:55:53 2019 +0100
genie: Fix parser's inner state when a struct is declared after a class
If the struct is declared after a class and has a default creation
method, the parser will raise a "missing return type in method ..."
error.
The cause of the bug is that the global 'class_name' variable is not
updated when the parser encounters a struct, so the previous value
is used, and if a class has been parsed before, this value will be the
name of the class instead of the struct.
tests/Makefile.am | 1 +
tests/genie/struct-after-class.gs | 13 +++++++++++++
vala/valagenieparser.vala | 2 ++
3 files changed, 16 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a574f2662..ce92b0d17 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -908,6 +908,7 @@ GENIE_TESTS = \
genie/preparser-not.gs \
genie/preparser-or-expression.gs \
genie/struct.gs \
+ genie/struct-after-class.gs \
$(NULL)
check-TESTS: $(TESTS) $(NON_NULL_TESTS)
diff --git a/tests/genie/struct-after-class.gs b/tests/genie/struct-after-class.gs
new file mode 100644
index 000000000..353012bc3
--- /dev/null
+++ b/tests/genie/struct-after-class.gs
@@ -0,0 +1,13 @@
+init
+ var a = new TestClass()
+ var b = TestStruct()
+ assert( a.empty == b.empty )
+
+class TestClass
+ empty:string = ""
+
+struct TestStruct
+ empty:string
+
+ construct()
+ empty = ""
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 9c7d72dd6..65ae04bd2 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -3290,6 +3290,8 @@ public class Vala.Genie.Parser : CodeVisitor {
expect (TokenType.EOL);
+ class_name = st.name;
+
parse_declarations (st);
Symbol result = st;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]