]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
genie: Fix parser's inner state when a struct is declared after a class 1384dd0bac5a93721e1ca11efed51fba4cb050ed
authorJeremy Philippe <jeremy.philippe@gmail.com>
Sat, 21 Dec 2019 19:55:53 +0000 (20:55 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 6 Jan 2020 08:29:36 +0000 (09:29 +0100)
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
tests/genie/struct-after-class.gs [new file with mode: 0644]
vala/valagenieparser.vala

index 8be08ce07589d885e36e57bc74b6dbdd4dcf4427..ebeeed0efdec759c083a29ef8c8572b55eac7170 100644 (file)
@@ -924,6 +924,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 (file)
index 0000000..353012b
--- /dev/null
@@ -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 = ""
index 668c404285febfd353cb5af7807684c7f98d4abc..6e6e9cd5c21ab215abe37316f6a25f913d1dc790 100644 (file)
@@ -3290,6 +3290,8 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                expect (TokenType.EOL);
 
+               class_name = st.name;
+
                parse_declarations (st);
 
                Symbol result = st;